• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cancel button in jsf

 
An Me
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added the following tag
<h:commandButton type="cancel" value="Cancel" action="/index" immediate="true"/>
which says use implicit navigation to go back to index.xhtml page.
While my index.xhtml page is in the WebContent folder, all others are in WebOcntent/pages/ folder.
On click of Cancel button, it is going back to index.xhtml page,but next time if I click on some other link in index.xhtml page,the path is not resolving correctly and throwing excpetion on browser 'Not Found in ExternalContext as a Resource'.

What is the solution ?
 
An Me
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention that in index.xhtml page I have many h:outputLink tags like
<h:outputLink value="pages/jsf-autofilling.xhtml">AutoFilling Demo</h:outputLink>
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are depending too much on your IDE, I think.

JSF handles the often annoying problem of addressing URLs within a web context by automatically adding the context when a JSF element has an "absolute" path. So "pages/jsf-autofilling.jsf" would be relative to the current page, but if the web application context is something like "http://www.javaranch.com/mywebapp", then "/pages/jsf-autofilling.jsf" would render in the actual HTML as "http://www.javaranch.com/mywebapp/pages/jsf-autofilling.jsf".

A couple of points about URLs.

A lot of people don't understand the difference between URLs and resources. A URL is what a client uses to make a web request to. Resources are what are used internally in the web application to satisfy the web requests. They are not the same thing, even though they are syntactically similar and often translatable.

The common convention is that JSF URLs end with the extension ".jsf" and JSF View Template definition resources end with ".xhtml". The JSF FacesServlet and its accompanying Facelet component will take in a URL such as "http://www.javaranch.com/mywebapp/pages/jsf-autofilling.jsf", break down the URL path to its application-relative form (/pages/jsf-autofilling.jsf), then convert that to the resource path (/pages/jsf-autofilling.xhtml). That resource is then used to build the component tree that will eventually render as the returned HTML page.

Some people wire up their web.xml so that ".xthml" is used in a URL instead of ".jsf", but that can be confusing and I'm not sure it's always safe.

Having said all that, you can skip the controversy by simply making your tag reference "/pages/jsf-autofilling", since in JSF2, the action processing already knows what you want without the need for an extension.


 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic