问题
How can I use view files with a different extension, other than XHTML, still map to the Faces Servlet in a JSF 2.0 application ?
I am migrating a JSF 1.2 app to 2.0, and I use file name extensions jspx. I dont want to change them to xhtml.
Thanks in advance for any help.
Here is my web.xml as of now
<?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>
回答1:
It is fixed.
The following code fixed it.
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.jspx</param-value>
</context-param>
And I got it from http://forums.oracle.com/forums/thread.jspa?threadID=2137307&tstart=90
Thanks Michael, for lending a hand.
回答2:
In your web.xml add this:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
来源:https://stackoverflow.com/questions/5416546/jsf-2-0-view-file-name-extension-other-than-xhtml