File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Cancel button in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Cancel button in jsf" Watch "Cancel button in jsf" New topic

Cancel button in jsf

An Me

Joined: Nov 28, 2013
Posts: 10
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

Joined: Nov 28, 2013
Posts: 10
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

Joined: Jun 25, 2001
Posts: 17417

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 "", then "/pages/jsf-autofilling.jsf" would render in the actual HTML as "".

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 "", 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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Cancel button in jsf
It's not a secret anymore!