• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mixing websites written in html and jsf

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic