This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes Should all HTML be banned from JSP pages in JSF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Should all HTML be banned from JSP pages in JSF?" Watch "Should all HTML be banned from JSP pages in JSF?" New topic
Author

Should all HTML be banned from JSP pages in JSF?

Saskia de Jong
Ranch Hand

Joined: Jan 24, 2006
Posts: 34
Recently I was transferred to a new project where I got an assignment to do some JSF stuff. After I checked in my code, I got a furious message from the project leader who told me HTML tags don't belong in JSF (when using it in a JSP file).

I'm not talking about making complex layouts by abusing tables, but just some rather innocent br tags between the JSF tags, e.g:



According to him, my JSF tree isn't 100% components anymore and styling should only be done through CSS in which br tags (among others) don't have any place. Now I'm rather confused. He sounds pretty convincing, but actually I don't see a lot of evidence on the net that shares this opinion. To the contrary, spec lead Ed Burns even uses the HTML table tag in his own examples and many textbooks use HTML mixed with JSF tags as well.

So I wonder how people out here think about this...
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167
As an emergency help - put <f:verbatim></f:verbatim> around your non-jsf content. I.e. something like <f:verbatim><br></f:verbatim>


To the contrary, spec lead Ed Burns even uses the HTML table tag in his own examples and many textbooks use HTML mixed with JSF tags as well.


We are speaking about JSF 1.1 and below at this point:
Most JSF tags do not allow non-jsf content inside (and without f:verbatim around). If you put the non-content inside, it will be pushed out. This happens because of the way show the component tree is rendered. There are three tags that still allow non-jsf content. Those are f:view f:form f:subview. If you looks closely to the examples where html tags are used you can find that there are no tags such as h anelGrid around.

JSF 1.2 addresses this problem. The way how the component tree is rendered has been changed there. At the same time, Facelets helps to work in mixed content even inside the JSF 1.1 environment.

--
Sergey : https://ajax4jsf.dev.java.net/
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The thing is, the page you have written will probably work.
Right up until the point where you include it as a subview in another page.

At that point, it will split up the "static" html, and the output from JSF, rather than intersperse them like you would traditionally expect.
ie the result would be something like


The verbatim tag adds it into the correct place in the component tree, so it will get generated as you expect.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should all HTML be banned from JSP pages in JSF?