Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit directory for JSF template files

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!

like image 230
Christian Seifert Avatar asked Nov 27 '25 19:11

Christian Seifert


1 Answers

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> 
like image 98
BalusC Avatar answered Nov 30 '25 08:11

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!