JSF 2.0查看除xhtml之外的文件扩展名

时间:2011-03-24 08:32:01

标签: jsf-2 richfaces web.xml

如何使用具有不同扩展名的视图文件(XHTML除外)仍然映射到JSF 2.0应用程序中的Faces Servlet?

我正在将JSF 1.2应用程序迁移到2.0,并且我使用文件扩展名jspx。我不想把它们改成xhtml。

提前感谢您的帮助。

这是我现在的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="JSF2Sample" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/app-tags.taglib.xml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

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

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

      <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>  

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>  
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>xcss</extension>
        <mime-type>text/css</mime-type>
    </mime-mapping>

</web-app>

2 个答案:

答案 0 :(得分:6)

它是固定的。

以下代码修复了它。

<context-param>
   <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
   <param-value>*.jspx</param-value>
</context-param>

我从http://forums.oracle.com/forums/thread.jspa?threadID=2137307&tstart=90

得到了它

感谢Michael,伸出援助之手。

答案 1 :(得分:3)

在你的web.xml中添加:

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