• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Starting with JSF 2.0 - Templates

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far so good with my (slow) progress in getting to grips with JSF 2.0.

Now I'm having problems with templates. I created the following file "main-template.xhtml" in a folder called "templates" below the WebContent folder in Eclipse:

And changed my "index.xhtml" file to the following:

But the "h" tags are not recognised by Eclipse. In case it was a problem with Eclipse, I closed it, reopened it, and ran "Validate" but the problem was not resolved. The applications also falis when I attempt to run it.

Obviously "index.xhtml" is not being able to find the "h" tag in the template file. As "main-template.xhtml" is in the subfolder "templates" the path should be "/templates/main-template.xhtml", so I'm wondering why it doesn't work. Does anybody have any ideas?

I looked at documentation at http://courses.coreservlets.com/Course-Materials/pdf/jsf/jsf2/JSF2-Facelets-Templating.pdf and http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/, amongst others.
 
Christopher Sharp
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I add the line xmlns:h="http://java.sun.com/jsf/html" at the top of "index.xhtml", then as expected the "h"tags are not flagged as an error by Eclipse and the page is displayed, but on attempting to click one of the links I get the message:

javax.servlet.ServletException: javax.el.PropertyNotFoundException: /index.xhtml @15,68 action="#{login.option1}": Target Unreachable, identifier 'login' resolved to null

so obviously that quick fix didn't work. Something most be wrong with the paths somewhere, but I don't know here.
 
Saloon Keeper
Posts: 28658
211
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
Do not confuse what your IDE wants with what the application wants. In production, the IDE won't be there. You can usually live with IDE errors (sometimes, in fact, you have little choice), but if the webapp isn't done right, it simply won't run right.

XHTML is an XML notation, and in XML, there is the concept of namespaces, where each namespace is identified by prefix tag (such as "h:" or "ui:") and mapped via the xmlns attribute to a URI. The URI provides a unique and unambiguous identifier for an XML tag schema. Kind of like a UUID/GUID, but in more human-readable terms.

The actual prefix itself isn't important, although there are conventions. If I wanted to, I could map the prefix "peterRabbit" to the JSF HTML core tagset and code things like this:


What is important is that the mapping be done properly. Like so:


The URI http://java.sun.com/jsf/html is compared against meta-information in the component library JARs (jsf-api.jar, for this one, I believe) in order to resolve the tagset schema.

That's basic JSF requirements. Without it, the webapp will fail. Getting Eclipse to not get annoyed with the http://java.sun.com/jsf/html URI requires configuring Eclipse itself to know where a copy of the associated schema can be found, and that's a question that should be asked in the Eclipse forum.
 
Christopher Sharp
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, many thanks, that clears up some questions. I'm aware that an IDE such as Eclipse may not resolve some links that are valid, and will run correctly on a server, but as you say, even if an IDE doesn't complain about a problem doesn't mean there isn't one, and ultimately what matters is how things run when deployed on a server.

In any case, I thought that if tags are defined in the namespace of a template file, that namespace will automatically be propagated to any file that makes use of the template.

I have posted a question on rollovers using Ajax in a new topic.
 
Tim Holloway
Saloon Keeper
Posts: 28658
211
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

Christopher Sharp wrote:
In any case, I thought that if tags are defined in the namespace of a template file, that namespace will automatically be propagated to any file that makes use of the template.



Nope. The namespaces are static definitions of XML and don't have any knowledge of other XML files (.xhtml files). So no propagation. Each .xhtml file stands alone. That's XML at work, not JSF.
 
Christopher Sharp
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, many thanks, and that will save me spending any more time on this.
reply
    Bookmark Topic Watch Topic
  • New Topic