aspose file tools*
The moose likes JSF and the fly likes Mixing websites written in html and jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Mixing websites written in html and jsf" Watch "Mixing websites written in html and jsf" New topic
Author

Mixing websites written in html and jsf

immer alvarado
Greenhorn

Joined: Nov 18, 2010
Posts: 9
Hello everyone.
I am a little confused with respects to jsf and html webpages; i hope someone can clarify for me. 1. How do i mix websites written in html,that are already written and running, with jsf 2.0? Do i just copy and paste the code from the website into the jsf facelets page code and let jsf assume the role of my website completely(assuming the copied/pasted code matches the requied xhtml syntax required by facelets)? Or can an entire website NOT be written in jsf (or within the facelets to be more technical)?
Thank you in advance, lol.
Mark Anthony Ranullo
Greenhorn

Joined: Dec 21, 2010
Posts: 6
immer alvarado wrote:Hello everyone.
I am a little confused with respects to jsf and html webpages; i hope someone can clarify for me. 1. How do i mix websites written in html,that are already written and running, with jsf 2.0? Do i just copy and paste the code from the website into the jsf facelets page code and let jsf assume the role of my website completely(assuming the copied/pasted code matches the requied xhtml syntax required by facelets)? Or can an entire website NOT be written in jsf (or within the facelets to be more technical)?
Thank you in advance, lol.


I'm not sure what you mean here but yes you could actually mix plain HTML into a JSF 2 page so as long as your HTML is a well formed XML because facelets do not accept malformed XML unless you change the default view technology used by the JSF 2.

Can an entire website NOT be written in JSF? Of course there's a lot of other alternatives out there. Unless the website your dealing with already has dependence on JSF. And yes you can write the code without facelets.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

JSF isn't greedy. If you have legacy code, you can safely leave it, even when the legacy code is for a completely different framework such as Struts. You can convert over to JSF slowly, one function at a time.

The only qualification I'd make on this is that when you convert an HTML-based page to JSF that you do the job as completely as possible and not mix HTML and JSF tags on the same page. You can do it (for the most part), but there are good reasons why that's not a good idea.


Customer surveys are for companies who didn't pay proper attention to begin with.
M Hunter
Greenhorn

Joined: Nov 24, 2010
Posts: 6
Tim Holloway wrote:The only qualification I'd make on this is that when you convert an HTML-based page to JSF that you do the job as completely as possible and not mix HTML and JSF tags on the same page. You can do it (for the most part), but there are good reasons why that's not a good idea.


Hey Tim,
I'm not questioning your comments, I'm just a new guy looking for wisdom.

I'm upgrading my project to JSF 2.0, and I'm trying to rid myself of the MyFaces and Tomahawk dependencies. I am using Tomahawks' <t:htmlTag value="" extensively throughout the code for things like ul, ol, li, p, etc. I came across this post and am curious what the good reasons are to avoid mixing HTML and JSF. I realize you have the clause "for the most part", but I am just curious as to avoid potential heart burn later on. Also, I fully realize I want to utilize the JSF tags when I can. I'm just curious what other options I have.

Thanks for your time,

Mick
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

OK. Welcome to the JavaRanch, BTW.

Just to clarify, mixing HTML pages and JSF pages in a webapp is not a problem. What I caution people against is mixing HTML and JSF tags on the same page.

There are several reasons. HTML is basically processed linearly. JSF is compiled into a tree structure, and the elements in that tree are JSF elements. In JSF 1.0, this would actually result in having a lot of the HTML dumped to one side or another of the JSF output, since the HTML and JSF would have been processed separately. That's what the <f:verbatim> element was designed to help with. Newer versions of JSF are more tolerant, so the "verbatim" tag isn't as important, although I still prefer to use it to wrap stylesheet and inline JavaScript blocks. And if anyone wants to assert that I have no business putting that much raw CSS and/or JavaScript directly on a JSF page, I won't contest it, but sometimes expediency wins out.

The other reason for avoiding HTML on a JSF page is that JSF is designed with the idea that the same JSF view definition should be portable to many different output media, with a plug-replaceable rendering layer taking responsibility for the final generated output. While almost all common JSF does generate HTML, consider a situation where a PDF renderer was plugged in instead. In this case, since PDF is based on PostScript and not on HTML tags, the HTML tags would simply print instead of being processed. So if you had 2 table definitions in a view, one done with dataTable or panelGrid JSF elements and one with brute-force HTML, the JSF items would display just fine, but the HTML items would show up as a bunch of garbage with lots of angle brackets in it.

Realistically, PDF is an unlikely renderer for JSF to be using, although I have an app that where I'd like to. More commonly, however, output might be targeted towards devices and applications for the vision-impaired, or even ("please stay on the line. Your call is very important to us! Press 1 to continue!") voice response units.
M Hunter
Greenhorn

Joined: Nov 24, 2010
Posts: 6
Thanks Tim, you present some good examples.

And just to remove any ambiguity, my questions are directly related to mixing JSF and HTML in the same page.

Your examples lead me to this question, "what are my options then to render things like <ul>, <ol>, <li>, <br>, <p>, etc. or in other words elements JSF doesn't render? I actually tried the <f:verbatim> tag over a couple <li> tags. I had the render attribute specified with some EL, and the <li> still rendered. I was able to get around this simply by rethinking the order of tags if you will, but maybe next time I wont be so lucky...what are my options?

Thanks again for your time Tim!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mixing websites written in html and jsf