0

我正在尝试将项目从 .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 的虚拟 url 模式。

我已经尝试过这里提到的修复

从 JSF 1.2 迁移到 JSF 2.0

和这里

在 JSF2 项目中混合 JSP 和 XHTML (Facelets) - 可能吗?

** *******完整的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>
4

1 回答 1

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 会自动用作“后备”。另请参阅从 JSF 1.2 迁移到 JSF 2.0。不要只看步骤或代码示例,还要仔细阅读文字。

于 2012-09-26T13:18:35.270 回答