views:

44

answers:

1

Hi everybody,

I'm just getting into Seam/JSF development and looking for a way to lookup the XHTML template files from a different location.

When configuring the JSF application like this:

<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.seam</url-pattern>
</servlet-mapping>

<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
</context-param>

when I enter a URL like:

http://localhost/test.seam

The system loads the XHTML file at

<webapp>/test.xhtml

What I'd like to configure is a prefix directory, so that the file is being looked up from

<webapp>/WEB-INF/views/test.xhtml

So, is there any way to achive something like this:

<context-param>
  <param-name>javax.faces.DEFAULT_PREFIX</param-name>
  <param-value>/WEB-INF/views/</param-value>
</context-param>

Thanks for your help!

+3  A: 

There isn't a way. I wish there was a way because preventing them from direct access by hiding them in /WEB-INF would have been very useful. I bet that this is also your actual functional requirement. You can achieve this by (ab)using declarative container managed security. Add a security-constraint on an url-pattern of *.xhtml with an empty auth-constraint to web.xml like follows:

<security-constraint>
    <display-name>Restrict direct access to XHTML files</display-name>
    <web-resource-collection>
        <web-resource-name>XHTML files</web-resource-name>
        <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint />
</security-constraint> 
BalusC
Nice workaround, but I guess this only works if the faces servlet is mapped to an extension different from xhtml. Do you know of any way to achieve this when the faces servlet is mapped to /faces or *.xhtml?
Jörn Horstmann
@Jörn: if the `FacesServlet` is mapped on `*.xhtml`, there's nothing to worry about. Accessing `*.xhtml` would then invoke `FacesServlet` **at any way** ;) But if it's mapped on `/faces` then your only resort is a `Filter` which checks both the folder and extension and handles accordingly (return 401 or 403). This can't be done nicely using declarative security.
BalusC