JSF标签是为.jsp而不是.xhtml页面呈现的

时间:2012-09-26 12:41:17

标签: jsp jsf facelets

我正在尝试逐渐将项目从.jsp转移到Facelets,但至少可以说有很多麻烦。

当前的jsf标记在.jsp页面上呈现得很好。

.xhtml页面带有简单的

<!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:p="http://primefaces.org/ui"> 

           <h:head>
                <title>This is a Test</title>    
             </h:head> 

           <h:body>
           <div>
                <H2>
                    <h:outputText value="test"/>
                </H2>
                </div>
        </h:body>
</html>

标题在尝试直接访问页面时会被呈现(somePage.xhtml),但 JSF标记永远不会被解析(检查页面显示JSF组件而不是html)。

尝试使用虚拟URL(somePage.cps)时,既不渲染标题也不渲染JSF标记。 (页面检查时不显示任何内容)

我一直在阅读的是因为JSF标签没有通过FacesServlet传递。

在我的web.xml中我有

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

让我说我是JSF的新手,这个项目传给了我,它正在使用.cps的虚拟网址模式。

我试过这里提到的修补程序

Migrating from JSF 1.2 to JSF 2.0

在这里

Mixing JSP and XHTML (Facelets) in JSF2 Project - possible?

** *******完整的WEB.XML ********** **

<?xml version="1.0" encoding="UTF-8"?>


<web-app 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">
    <display-name>Copyright 2012 University of Kentucky</display-name>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/config/jsf/faces-config.xml</param-value>
    </context-param>
    <context-param>
        <param-name>org.ajax4jsf.DEFAULT</param-name>
        <param-value>classic</param-value>
    </context-param>
    <!-- Define the basename for a resource bundle for I18N -->
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>messages</param-value>
    </context-param>
    <!-- Plugging the "Blue Sky" skin into the project -->

    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>glassX</param-value>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.ERROR_HANDLER</param-name>
        <param-value>edu.uky.cepis.util.global.error.JSFCustomErrorHandler</param-value>
    </context-param>

    <!-- Making the RichFaces skin spread to standard HTML controls -->
    <context-param>
        <param-name>org.richfaces.CONTROL_SKINNING</param-name>
        <param-value>enable</param-value>
    </context-param>

    <!-- 1. Setup two parameters: -->
    <!-- b) Logging configuration file -->
    <!-- b) Spring configuration file -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/spring/cepis-*</param-value>
    </context-param>

    <context-param>
        <param-name>contextFactory</param-name>
        <param-value>
            com.tonbeller.wcf.controller.RequestContextFactoryImpl
        </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>*.cps</url-pattern>
    </servlet-mapping>


    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <!-- Defining and mapping the RichFaces filter -->
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
        <init-param>
            <param-name>createTempFiles</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>maxRequestSize</param-name>
            <param-value>100000000</param-value>
        </init-param>
    </filter>
    <!-- Filter for AJAX4JSF <filter> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> 
        </filter> -->
    <filter>
        <filter-name>hibernateViewFilter</filter-name>
        <filter-class>
            org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
        </filter-class>
    </filter>

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter>
        <filter-name>ResponseOverrideFilter</filter-name>
        <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
    </filter>

    <filter>
        <filter-name>JPivotController</filter-name>
        <filter-class>com.tonbeller.wcf.controller.RequestFilter</filter-class>
        <!-- <init-param> <param-name>indexJSP</param-name> <param-value>/index.html</param-value> 
            <description> forward to this page if session is new </description> </init-param> 
            <init-param> <param-name>errorJSP</param-name> <param-value>/error.jsp</param-value> 
            <description>URI of error page</description> </init-param> <init-param> <param-name>busyJSP</param-name> 
            <param-value>/busy.jsp</param-value> <description> This page is displayed 
            if a the user clicks on a query before the previous query has finished </description> 
            </init-param> <init-param> <param-name>forceExtension</param-name> <param-value>.faces</param-value> 
            <description>replace .jsp with .faces</description> </init-param> -->
    </filter>
    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
            <!-- <description>Set the size limit for uploaded files.Format: 10 - 10 
                bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB</description> -->
        </init-param>
        <init-param>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>


    <filter>
        <filter-name>Spring character encoding filter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>


    <!-- Richfaces 3.3.3 Firefox 11 Patch -->
    <filter>
        <filter-name>RichFacesFirefox11Filter</filter-name>
        <filter-class>edu.uky.cepis.filter.patch.RichFacesFirefox11Filter</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>hibernateViewFilter</filter-name>
        <url-pattern>*.cps</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <!-- <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces 
        Servlet</servlet-name> </filter-mapping> -->
    <filter-mapping>
        <filter-name>JPivotController</filter-name>
        <url-pattern>/jpivot.action</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>JPivotController</filter-name>
        <url-pattern>/JPivot.jsp</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>ResponseOverrideFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/pages/report/*</url-pattern>
    </filter-mapping>

    <!-- Do not remove this. Needed for proper functioning of struts -->
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/struts/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>Spring character encoding filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- extension mapping for adding <script/>, <link/>, and other resource 
        tags to JSF-pages -->
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>RichFacesFirefox11Filter</filter-name>
        <url-pattern>*.cps</url-pattern>
    </filter-mapping>

    <!-- resources initializer -->
    <listener>
        <listener-class>
            com.tonbeller.tbutils.res.ResourcesFactoryContextListener
        </listener-class>
    </listener>

    <!-- 3. Setup three listeners -->
    <!-- a) Setup a listener to connect spring with the web context -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener> 
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <!-- b) Setup a listener to connect spring with log4J -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- c) Setup ACEGI to subscribe to http session events in the web context 
        <listener> <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class> 
        </listener> -->
    <listener>
        <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
    </listener>
    <!-- Spring Security Concurrent Session Listener -->
    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

    <!-- CAS Authentication -->
    <!-- <servlet> <servlet-name>casproxy</servlet-name> <servlet-class>edu.yale.its.tp.cas.proxy.ProxyTicketReceptor</servlet-class> 
        </servlet> -->
    <!-- Faces Servlet -->


    <!-- Servlet for Report Module -->
    <servlet>
        <servlet-name>JspSupportServlet</servlet-name>
        <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>fileServlet</servlet-name>
        <servlet-class>org.efs.openreports.dispatcher.FileDispatcher</servlet-class>
        <load-on-startup>99</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>MondrianXmlaServlet</servlet-name>
        <servlet-class>org.efs.openreports.dispatcher.XMLADispatcher</servlet-class>
    </servlet>

    <servlet>
        <servlet-name>XFireServlet</servlet-name>
        <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
    </servlet>

    <!-- jfreechart provided servlet -->
    <servlet>
        <servlet-name>DisplayChart</servlet-name>
        <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
    </servlet>

    <!-- jfreechart provided servlet -->
    <servlet>
        <servlet-name>GetChart</servlet-name>
        <servlet-class>com.tonbeller.jpivot.chart.GetChart</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>Print</servlet-name>
        <servlet-class>com.tonbeller.jpivot.print.PrintServlet</servlet-class>
    </servlet>

    <!-- EPSB Coldfusion access using Railo -->
    <servlet>
        <servlet-name>CFMLServlet</servlet-name>
        <servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
        <init-param>
            <param-name>configuration</param-name>
            <param-value>{web-root-directory}/WEB-INF/railo/</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>SpringServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>




    <!-- CAS Servlet Mapping -->
    <!-- <servlet-mapping> <servlet-name>casproxy</servlet-name> <url-pattern>/casProxy/*</url-pattern> 
        </servlet-mapping> -->
    <!-- Faces Servlet Mapping -->

    <servlet-mapping>
        <servlet-name>DisplayChart</servlet-name>
        <url-pattern>/DisplayChart</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Print</servlet-name>
        <url-pattern>/Print</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>GetChart</servlet-name>
        <url-pattern>/GetChart</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>fileServlet</servlet-name>
        <url-pattern>/report-images/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>fileServlet</servlet-name>
        <url-pattern>/report-files/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>MondrianXmlaServlet</servlet-name>
        <url-pattern>/xmla</url-pattern>
    </servlet-mapping>


    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfc</url-pattern>
    </servlet-mapping>
    <!-- Spring Batch Admin -->
    <servlet-mapping>
        <servlet-name>SpringServlet</servlet-name>
        <url-pattern>/batch/*</url-pattern>
    </servlet-mapping>


    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.cps</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>


</web-app>

1 个答案:

答案 0 :(得分:0)

删除以下上下文参数(不要忘记先撤消Stephan提出的错误更改)。

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

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

第一个基本上是告诉JSF应该使用JSP作为默认视图技术,因此Facelets永远不会被识别/使用。你当然不希望这样。第二个是默认值,但如果第一个设置为这样,则无效。只需删除它们。 JSF 2.0已默认为Facelets(XHTML)。此外,当Facelets被用作默认视图技术时,JSP会自动用作“后备”。另见Migrating from JSF 1.2 to JSF 2.0。不仅要查看步骤或代码示例,还要仔细阅读文本。