3 Replies Latest reply on Nov 15, 2007 10:14 AM by Kin Leung

    How to make RichFaces and Facelet work together

    Kin Leung Newbie

      I am trying to build an app using RichFaces (3.1.2 GA), Facelet (1.1.13), and MyFaces. I am struggling to make the app working, as the page cannot be rendered. From the log file I see a null pointer exception
      ERROR 14:54:55 [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/cre-facelet].[FacesServlet]] - Servlet.service() for servlet FacesServlet threw exception
      java.lang.NullPointerException
      at org.ajax4jsf.application.AjaxViewHandler.createView(AjaxViewHandler.java:85)
      at org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:144)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.jav

      I google searched around and see one recommendation is to add
      <context-param>
      <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
      <param-value>com.sun.facelets.FaceletViewHandler</param-value>
      </context-param>
      in web.xml and remove the <view-handler> setting in faces-config.xml. Still it does not work. Here is my web.xml and faces-config.xml

      web.xml:
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      <display-name>cre-facelet</display-name>
      <![CDATA[${pom.name}]]>


      <context-param>

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

      <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
      <param-value>true</param-value>
      </context-param>
      <context-param>

      <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
      <param-value>true</param-value>
      </context-param>
      <context-param>

      <param-name>facelets.LIBRARIES</param-name>
      <param-value>/WEB-INF/taglib/tomahawk.taglib.xml</param-value>
      </context-param>
      <context-param>

      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-cre-facelet.xml</param-value>
      </context-param>
      <context-param>

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

      <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
      <param-value>com.sun.facelets.FaceletViewHandler</param-value>
      </context-param>


      <filter-name>ExtensionsFilter</filter-name>
      <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
      <init-param>
      <param-name>uploadMaxFileSize</param-name>
      <param-value>10m</param-value>
      </init-param>
      <init-param>
      <param-name>uploadThresholdSize</param-name>
      <param-value>100k</param-value>
      </init-param>


      <filter-name>RichFacesFilter</filter-name>
      <filter-class>org.ajax4jsf.Filter</filter-class>


      <filter-mapping>
      <filter-name>ExtensionsFilter</filter-name>
      <servlet-name>FacesServlet</servlet-name>
      </filter-mapping>
      <filter-mapping>
      <filter-name>RichFacesFilter</filter-name>
      <servlet-name>FacesServlet</servlet-name>
      REQUEST
      FORWARD
      INCLUDE
      </filter-mapping>
      <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
      <filter-mapping>
      <filter-name>ExtensionsFilter</filter-name>
      <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
      </filter-mapping>

      <!-- extension mapping for adding , , and other resource tags to JSF-pages -->
      <filter-mapping>
      <filter-name>ExtensionsFilter</filter-name>
      <url-pattern>*.jsf</url-pattern>
      </filter-mapping>

      <filter-mapping>
      <filter-name>ExtensionsFilter</filter-name>
      <url-pattern>*.faces</url-pattern>
      </filter-mapping>


      <listener-class>
      org.apache.myfaces.webapp.StartupServletContextListener
      </listener-class>


      <listener-class>
      org.springframework.web.context.ContextLoaderListener
      </listener-class>


      <!-- Faces Servlet -->

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


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

      <!--
      To specify mime mappings, create a file named mime-mappings.xml, put it in your project's mergedir.
      Organize mime-mappings.xml following this DTD slice:

      <!ELEMENT mime-mapping (extension, mime-type)>
      -->

      <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>welcome.faces</welcome-file>
      </welcome-file-list>

      <!--
      To specify error pages, create a file named error-pages.xml, put it in your project's mergedir.
      Organize error-pages.xml following this DTD slice:

      <!ELEMENT error-page ((error-code | exception-type), location)>
      -->

      <!--
      To add taglibs by xml, create a file called taglibs.xml and place it
      in your merge dir.
      -->

      <!--
      To set up security settings for your web app, create a file named web-security.xml, put it in your project's mergedir.
      Organize web-security.xml following this DTD slice:

      <!ELEMENT security-constraint (display-name?, web-resource-collection+, auth-constraint?, user-data-constraint?)>
      <!ELEMENT web-resource-collection (web-resource-name, description?, url-pattern*, http-method*)>
      <!ELEMENT web-resource-name (#PCDATA)>
      <!ELEMENT url-pattern (#PCDATA)>
      <!ELEMENT http-method (#PCDATA)>
      <!ELEMENT user-data-constraint (description?, transport-guarantee)>
      <!ELEMENT transport-guarantee (#PCDATA)>

      <!ELEMENT login-config (auth-method?, realm-name?, form-login-config?)>
      <!ELEMENT auth-method (#PCDATA)>
      <!ELEMENT realm-name (#PCDATA)>
      <!ELEMENT form-login-config (form-login-page, form-error-page)>
      <!ELEMENT form-login-page (#PCDATA)>
      <!ELEMENT form-error-page (#PCDATA)>
      -->

      </web-app>

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

      <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
      <faces-config>

      <managed-bean>
      <managed-bean-name>bean</managed-bean-name>
      <managed-bean-class>com.snp.cre.ui.EchoBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      <!-- If you have non XDoclet beans, define them in a file called jsf-beans.xml and place it in your merge directory. -->

      <!-- If you have non XDoclet navigation rules, define them in a file called jsf-navigations.xml and place it in your merge directory. -->


      <variable-resolver>
      org.springframework.web.jsf.DelegatingVariableResolver
      </variable-resolver>
      <message-bundle></message-bundle>
      <locale-config>
      <default-locale>en</default-locale>
      </locale-config>
      <!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler-->


      <!-- If you have non XDoclet validators, define them in a file called jsf-validators.xml and place it in your merge directory. -->

      <!-- If you have non XDoclet converters, define them in a file called jsf-converters.xml and place it in your merge directory. -->

      <!-- If you have non XDoclet components, define them in a file called jsf-components.xml and place it in your merge directory. -->

      <!-- If you have non XDoclet render-kits, define them in a file called jsf-render-kits.xml and place it in your merge directory. -->
      </faces-config>

      Any one has any idea?