• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Lee
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/*
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Lee
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your points. They are very helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic