aspose file tools*
The moose likes JSF and the fly likes Using HTML tags in XHTML (JSF) pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Using HTML tags in XHTML (JSF) pages" Watch "Using HTML tags in XHTML (JSF) pages" New topic
Author

Using HTML tags in XHTML (JSF) pages

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 159

Hi,

Is it ok to use regular HTML tags in XHTML files for JSF? I have purchased a book to get me started with JSF and some of the template examples line out the template using HTML <div> tags. I would have assumed that I would have had to use <h:panelgroup layout ="block"> to render the <div> tags? Does best practice with JSF tell us not to mix markup tags? I have seen many examples now where XHTML pages are mixed with regular HTML tags and JSF tags now. I don't want to start learning bad habits this early!

Thanks,
Alan
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

I do not recommend mixing them for several reasons, but it can be a struggle to remain "ideologically pure" (retch!).

There are several reasons why JSF-only is better:

1. Unlike straight HTML, JSF2 uses XML-format View Templating. Vanilla HTML has very sloppy formatting rules - no case sensitivity, no enforcement of tag closures, no mandatory quotes around attribute values, etc. In fact, HTML tends to give XML editors heartburn, so most people use xhtml (the w3x standard, not to be confused with the ".xhtm" Facelets standard file extension).

2. As originally designed, JSF made a great distinction between the presentation and the execution of tags, employing plug-replaceable renderers to generate the actual HTML. As long as everything is pure JSF, switching to, say, a PDF renderer is pretty straightforward, since the PDF renderers would output the JSF elements as PDF. But any HTML tags wouldn't be processed by JSF, therefore they'd be propagated unchanged into the final PDF, where, since PDF is based on PostScript and not on HTML, they would be visible in their original ugly form - angle brackets and all - instead of being rendered into their graphic equivalents.

There are, however, also several reasons why 100% pure JSF can be difficult.

1. In JSF1, certain critical HTML tags such as the head and body tags had no JSF equivalent. So it was HTML or nothing. In JSF2, if you use the HTML head and body tags instead of the JSF head and body tags, the view won't render properly, however!

2. JSF2 adds Facelets and Facelets unabashedly supports HTML and doesn't really care about alternative renderers. So the rationale for avoiding mixed tags is reduced.

3. There are certain things pertaining to layout that may be difficult to do without recourse to raw HTML. I have a very especial gripe against Red Hat JBoss RichFaces 4 on that score. RichFaces 3 had 2 layout-supportive tags for spacers and rules that were quite deliberately removed from RichFaces 4. Their rationale was that since these were graphical and not functional, they didn't belong and should be replaced with raw HTML equivalents. To which I reply, "see above".


Customer surveys are for companies who didn't pay proper attention to begin with.
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 159

Hi Tim,

thanks for the reply. I will stick with using all JSF tags until I come across a good reason to revert to HTML tags in my projects. I will be using PrimeFaces as well more than likely, their component library looks great. I will be back with more JSF questions and headaches sooner rather than later ;)

Cheers,
Alan
 
 
subject: Using HTML tags in XHTML (JSF) pages