This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

JSF Navigation question

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers!

Truthfully I'm fairly new to the java scene and am currently putting together a basic project however am a little bit confused in regards to navigation within my JSF project.

Currently I have four files inside my project, calulator, reservations, WEB-INF and META-INF and in this same location, two .xhtml files which provide links to navigate to JSP pages inside the reservations folder.

Currently I believe I'm using implicit navigation between the two .xhtml pages (button that acceses a bean String that returns a page name) however how would I go about navigating from a JSP page to a .xhtml file one up the file hierarchy?

I realise this is a fairly basic issue and has probably been asked before so apologies in advance!


webapp - calculator (empty)
-reservations - contains JSP pages as mentioned above
-Welcome.xhtml (which I'm looking to navigate to/link to from said JSP page!)
Saloon Keeper
Posts: 25466
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
Welcome to the the JavaRanch, Sam!

First of all, you don't navigate xhtml, which is a resource, you navigate URLs. People get resources and URLs confused because both of them are addressed by similar path syntax, but one is the physical definition of code or data and the other is what the client requests from the server.

Web conventions make that additionally confusing since the default action for a server when receiving a URL is to attempt to find a resource with the same path and name, although in the case of JSF the facelets filter actually wants to take something like path/resource.jsf, translate it to path/resource.xhtml, retrieve path/resource.xhtml and compile it into a JSF View.

Now that I've got all the pedantry out of the way, the way you navigate "uphill" on JSF URLs is the same way you do with files. Via the "parent directory" convention. So, reservations/Reserve.jsf could find Welcome.jsf in the root via the relative URL "../Welcome.jsf", the JSF navigation string "../Welcome", a JSF logical navigation target mapped in faces-config.xml (name it something like "Welcome" or "home"). Which is a good abstraction.

OR use the absolute path: "/Welcome.jsf" or its navigation equivalent "/Welcome".

And as a final note, one convenience that JSF offers is that absolute URLs within a JSF webapp are "absolute" relative to the application context path, which means that you don't have to know what context your webapp is deployed under.

And incidentally, you cannot navigate up above your webapp root and potentially down into the directories of other Tomcat apps or other filesystem objects. For security reasons, the world ends at the webapp root.
Sam Williams
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Thanks a million for your informative post, I'm still getting to grips with everything and found it very helpful and informative!

Huge help, I'll continue to learn more into it as I go! :)

Thanks again,
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic