开发者

Explicit directory for JSF template files

开发者 https://www.devze.com 2023-01-08 17:50 出处:网络
I\'m just getting into Seam/JSF development and looking for a way to lookup the XHTML template files from a different location.

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>j开发者_JAVA技巧avax.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!


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> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号