JSF2.0 + Richfaces + Facelet是否正确?

时间:2012-01-12 07:04:41

标签: jsf-2 richfaces tomcat6 facelets

我使用以下环境创建简单项目。 1. Netbeans IDE6.9.1(文件 - > NewProject->选择JSF2.0库)

  1. Tomcat 6.0.29
  2. 罐子
    1.Commons-BeanUtils的-1.7.0.jar
    2.commons的集合-3.2.jar
    3.commons沼气池-1.8.jar
    4.commns测井-1.0.4.jar
    5.el-funstions.jar
    6.jhighlight.jar
    7.cssparser-0.9.5.jar
    8.guava-r09.jar
    9.sac-1.3.jar
    10.richfaces-API 3.3.3.Final.jar
    11.richfaces-IMPL-3.3.3.Final.jar

    12.richfaces-ui-3.3.3Final.jar
    13.jsf-facelets-1.1.15.B1.jar
    14.JSF 2.0-jsf-api.jar
    15.JSF2.0-jsf-impl.jar
    16.JSTL 1.1-Standard.jar
    17.JSTL 1.1- jstl.jar
    

    的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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</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>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <!--Configuration for Richfaces-->
    
    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>blueSky</param-value>
    </context-param>
    
    
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <!--End of the configuration part for Richfaces-->
    
     <!--Configuration for Facelets-->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <!--End of the configuration part for Facelets-->
    
     <!-- The following attribute facelet    -->
    <context-param>
        <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
        <param-value>true</param-value>
    </context-param>
    <!-- End of The following attribute facelet    -->
    </web-app>
    

    faces-config.xml中

    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.0"
    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-facesconfig_2_0.xsd">
    <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>
    </faces-config>
    

    index.xhtml文件

    <?xml version='1.0' encoding="UTF-8'?>
    <!DOCTYPE html PUBLIC "-//W#C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:rich="http://richfaces.org/rich">
    <h:body>
                 Hello Facelet
                 <h:outputText value="Sample output text"/>
                 <rich:panel>
                       <f:facet name="header">
                              <h:outputText value="Sample Panel"/>
                        </f:facet>
    
                         <h:outputText value="Panel content added here"/>
                  </rich:panel>
    <h:body>
    </html>
    

    当我运行我的项目时,我收到以下错误。 而且我也不知道上面的配置和罐子是否正确。

    javax.servlet.ServletException: Illegal attempt to set ViewHandler after a response has been rendered.
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
    org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered.
    com.sun.faces.application.ApplicationImpl.setViewHandler(ApplicationImpl.java:562)
    org.ajax4jsf.event.InitPhaseListener.beforePhase(InitPhaseListener.java:92)
     com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
     com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
     com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
     com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
     javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
     org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
     org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
     org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
     org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    

    帮帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:2)

faces-config.xml 中的视图处理程序设置更改为

<application>
  <view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
</application>