This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF Navigation question  RSS feed

 
Sam Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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!

Hierarchy:

webapp - calculator (empty)
- META-INF
-reservations - contains JSP pages as mentioned above
-WEB-INF
-Welcome.xhtml (which I'm looking to navigate to/link to from said JSP page!)
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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,
Sam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!