Using class attribute instead of styleClass of a JSF component actually works, why? - class

As far as I understood, we needed to use styleClass= as the JSF components don't support using just class=.
I've noticed recently that some components that were using class= were still rendering correctly. As a minimal example,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Simple JSF Facelets page</title>
</h:head>
<h:body>
<h:inputText class="wut" anothertag="hi" value="me"/>
</h:body>
</html>
This produces
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="/individuallifefaz/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo"/>
<title>Simple JSF Facelets page</title></head>
<body>
<input type="text" name="j_idt5" value="me" class="wut"/>
</body>
</html>
Why is this working? It's clearly not just passing through any unknown tags, as the anothertag is stripped out.

This is actually done by the view technology Facelets, not by the JSF component itself. Facelets has an alias for class attribute which automatically maps to styleClass. This was implemented as part of support for jsfc attribute as used in "designer friendly Facelets" which should make things like this possible:
<input type="text" jsfc="h:inputText" class="foo" />
If you use JSF with a different view technology (although so far there's none which is a serious alternative to Facelets, and JSP is deprecated), then there's no guarantee that <h:inputText class> would work.
See also:
Is there a way to run a JSF page without building the whole project?

Related

Image is not displayed in html inside jsp

I am trying to display a image in html in JSP script, just using img tag.
index.jsp code:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="topbar">
<img src="images/x.png" alt="img" height="30" width="25">
</div>
</body>
</html>
I ma using eclipse neon (apache-tomcat local server in Ubuntu) and my directory structure is :
When I run index.jsp , image is not displayed. What I am doing wrong?
Please ask me if you need more information.
#user3138997 gave me hints:
I just need to write as:
<img src="/projectName/images/x.png" alt="img" height="30" width="25">
And this shows the image.

Posting form to an iframe under strict XHTML (firefox)

For debug purposes, I run my page under strict XHTML while I develop it. But, right now, I realised, that such code will not work:
<!-- With header("Content-Type: application/xhtml+xml; charset=\"utf-8\"") -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!--blah blah blah-->
</head>
<body>
<form method="post" target="my_frame">
<button>Send the form!</button>
</form>
<iframe name="my_frame" src="about:blank"></iframe>
</body>
</html>
Try it here. And also try it with text/html content-type. I can, of course, disable the strict mode for the site, but here on SO my question is, how to get it to work a XHTML. (this means, how to make the 1. link work properly).
Fun fact: While testing the example, I noticed that <button> tag does not work in IE properly. Any ideas what's wrong? (that's side question of course)
For XHTML, use id rather than name as the attribute for the target on the iframe. For HTML/XHTML compatibility, use both a name and an id and make sure their values are the same.
However, take note that target is not a valid attribute on a form. So it won't validate, and its working is not guaranteed.
The IE one should have been another question, but IE needs type="submit" for buttons, even if that type is supposed to be the default.

Facebook namespace problem causing invalid code

I have seen various articles on this site and on google about how to make facebook code valid, but none of the solutions seem to work for me.
I think the problem lies in my doc type decleration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" >
...
<meta property="og:site_name" content="my site name" />
<meta property="og:title" content="Buy...
Can anyone point me in the right direction please?
John
I'm having a similar problem.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xml:lang="nl-NL">
...
<meta property="og:type" content="book" />
That's how almost all examples are like, and strangely it validates on w3c's validator, however all other validators including CSE Html validator and http://check.rdfa.info need a og prefix in front of the meta tag:
<og:meta property="og:type" content="book" />
That validates in almost anything except the official w3c validator. Not sure if facebook will parse it either. Why they chose not to use "name" is a big mystery for me. What a fine mess!

Is this XHTML document valid for parsing with the iPhone

I would be grateful if someone could clarify if this document is valid for xhtml parsing using the iphone SDK using xpaths:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>East Lancs Radio - Now Playing</title>
<META HTTP-EQUIV="REFRESH" CONTENT="45">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="player-currently-playing">
Currently Playing
<div class="player-track">
Lush
</div>
<div class="player-artist">
Ladykillers
</div>
</div>
<div id="player-playing-next">
Playing Next
<div class="player-track">
Javine
</div>
<div class="player-artist">
Surrender (Your...
</div>
</div>
</body>
</html>
I'm trying to extract the currently playing player-track 'lush' and player-artist 'ladykillers' through using xpath. If I do an xpath search for: //#class and then print the result to screen, I get player-track, player-artist.. etc outputted?
Am I missing something fairly obvious here?
Thanks
Dan
The W3C Markup Validation Service comes up with 9 errors in this document.
So, this is not a valid XHTML document, for iPhone usage or otherwise.
Your XPath result is giving you what you're asking for which is the values of the class attributes.
To get the currently playing player-track use:
//*[#id = 'player-currently-playing']/*[#class = 'player-track']/text()
and to get the currently playing player-artist use:
//*[#id = 'player-currently-playing']/*[#class = 'player-artist']/text()

Why does this XHTML-MP code not pass W3C validation?

Wikipedia's example of XHTML-MP:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN"
"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello</title>
</head>
<body>
<p>Hello world.</p>
</body>
</html>
This fails W3C validation with the error Input is not proper UTF-8, indicate encoding ! Bytes: 0xA9 0x20 0x32 0x30
Even if you add <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> and tell the validator it's UTF8, it gives this error.
If the XHTML-MP DOCTYPE is removed, it works fine. What is the deal?
The problem is with the external DTD. If you change the DOCTYPE to this, it validates:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
http://mobiready.com/launch.jsp?locale=en_EN validates it fine. Wierd
Also you don't need to use 1.1 in order to use JavaScript. Although it wouldn't validate on W3's checker,
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
works just fine with almost all JavaScript supported phones.