wood burning stoves 2.0*
The moose likes JSF and the fly likes /faces/* url pattern and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "/faces/* url pattern and "The requested resource () is not available." error" Watch "/faces/* url pattern and "The requested resource () is not available." error" New topic
Author

/faces/* url pattern and "The requested resource () is not available." error

James Lee
Ranch Hand

Joined: Oct 16, 2006
Posts: 36
Hi,

I'm using JSF 2.0. Something is weird with servlet-mapping setting.

If I use *.jsf url pattern (see below), .../hello.jsf url works fine.

However, if I use /faces/* url pattern (see below), .../faces/hello yields "The requested resource () is not available." error.

I want to use folder-structure url in my 2nd case, i.e., no extension in the url.

Based on the settings, .../hello.jsf and .../faces/hello should result in the same page from hello.xhtml. Does anyone know what's going wrong there?

Many thanks!
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

When you use /faces/* mapping to run your page through FacesServlet you should simply provide full name of your file - hello.xhtml instead of hello
When you used *.jsf mapping you had to append '.jsf' to hello to have page processed by FacesServlet.
I want to use folder-structure url in my 2nd case, i.e., no extension in the url

I found this url in the Internet - http://javawords.com/2007/10/02/mapping-facesservlet-to-urls-without-extensions/

I find more convenient to use .xhtml extension because every my page is guaranteed to run through FacesServlet:

IF you have page with extension .xhtml and your FacesServlet is mapped to .jsf or /faces/* patterns, then user can type in browser path to your file directly
and server will return your page without running it through FacesServlet. Of course it is not possible if your page on server is inside folder 'faces' for /faces/*


True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

When you submit a URL request to a JSF app and the URL matches one of the pattern(s) that get it routed to the FacesServlet, the FacesServlet (along with the Facelets processor) deconstruct the URL path and use it as the framework to build up a resource path. There are several built-in rulesets, the most commonly-used one being that which takes URLs ending with ".jsf" and resolves them with resources whose paths are the same as the local part of the URL path only with the ".jsf" replaced by ".xhtml".

You can modify those rules, but one easier way to be able to employ simple URLs such as "http://www.mousetech.com/nosuchapp/widget/new" or "http://www.coderanch.com/forums/posts/reply/0/597582" is to add PrettyFaces to your webapp. PrettyFaces is a JSF add-on that allows the creation of bookmarkable URLs. It's basically just a jar, a small mod to web.xml, and a config file that contains the URL mappings (these days you can also annotate backing beans). Very easy to use.


Customer surveys are for companies who didn't pay proper attention to begin with.
James Lee
Ranch Hand

Joined: Oct 16, 2006
Posts: 36
Thanks a lot for your points. They are very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: /faces/* url pattern and "The requested resource () is not available." error