3 Replies Latest reply on Jan 31, 2008 8:10 AM by Viggo Navarsete

    Caused by: javax.faces.application.ViewExpiredException: vie

    Viggo Navarsete Expert

      I have a Richfaces portlet that basically consists of one page (start.xhtml) where there is one input field and a button. When the user push the button my SearchBean's search method is executed. Right now I'm just returning the string "success" (to test it), and then the user is supposed to get the start.xhtml displayed once more, but now with a search result below the search input. I'm getting this ViewExpiredException when pushing the button. What I've done so far is:
      1. In portlet.xml I have configured /start.xhtml to be my first page of my portlet. I guess since it's first page the user visits, it got be be places outside the WEB-INF directory? Please correct me if I'm wrong about this! Ideally I would like to put all mye *.xhtml in a folder with subfolders, like jsf/. Well, based on my assumptions, I have places my start.xhtml on the root of my war file as you will see.

      <portlet-app version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/portlet"
       xmlns="http://java.sun.com/xml/ns/portlet">
       <portlet>
       <portlet-name>searchPortlet</portlet-name>
       <portlet-class>
       javax.portlet.faces.GenericFacesPortlet
       </portlet-class>
      
       <init-param>
       <name>javax.portlet.faces.defaultViewId.view</name>
       <value>/start.xhtml</value>
       </init-param>
      
       <expiration-cache>-0</expiration-cache>
       <portlet-info>
       <title>GTNet search</title>
       </portlet-info>
       <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
       </supports>
       </portlet>
      </portlet-app>


      2. My start.xhtml looks like this:
      <f:view contentType="text/html"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:r="http://richfaces.org/rich">
       <a4j:portlet>
       <html>
       <body>
       <h:form>
       <r:panel>
       <f:facet name="header" >
       <f:verbatim>Search input</f:verbatim>
       </f:facet>
       <table>
       <tr>
       <td>
       <h:outputLabel for="searchInputString" value="Search input"/>
       </td>
       <td>
       <h:inputText id="searchInputString" value="#{searchBean.searchString}" size="40"/>
       <h:commandButton action="#{searchBean.search}" value="Search" immediate="true"/>
       </td>
       </tr>
       </table>
       </r:panel>
       </h:form>
       </body>
       </html>
       </a4j:portlet>
      </f:view>


      3. My web.xml looks like this:
      <?xml version="1.0"?>
      <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">
      
       <description>RichFacesPortlet</description>
      
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>wine</param-value>
       </context-param>
       <context-param>
       <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
       <param-value>org.ajax4jsf.portlet.application.FaceletPortletViewHandler</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.LoadStyleStrategy</param-name>
       <param-value>NONE</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.LoadScriptStrategy</param-name>
       <param-value>NONE</param-value>
       </context-param>
      
       <context-param>
       <param-name>facelets.DEVELOPMENT</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.SKIP_COMMENTS</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.VIEW_MAPPINGS</param-name>
       <param-value>*.xhtml</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>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
       </context-param>
      
       <!--context-param>
       <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
       <param-value>true</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>FacesServlet</servlet-name>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
      
       <listener>
       <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
       </listener>
       <servlet>
       <servlet-name>FacesServlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
       <servlet-name>FacesServlet</servlet-name>
       <url-pattern>/faces/*</url-pattern>
       </servlet-mapping>
      
       <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
       classpath:custom-business-config.xml,classpath:tbu-mock.xml
       </param-value>
       </context-param>
       <listener>
       <listener-class>
       org.springframework.web.context.ContextLoaderListener
       </listener-class>
       </listener>
      </web-app>


      4. My faces-config.xml looks like this:
      <?xml version='1.0' encoding='UTF-8'?>
      <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xi="http://www.w3.org/2001/XInclude"
       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_1_2.xsd">
      
       <managed-bean>
       <description>
       The bean that backs up the Search portlet
       </description>
       <managed-bean-name>searchBean</managed-bean-name> <managed-bean-class>com.foo.dashboard.gui.SearchBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
       <navigation-rule>
       <from-view-id>start.xhtml</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>start.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <render-kit>
       <renderer>
       <description>override the viewroot</description>
       <component-family>javax.faces.ViewRoot</component-family>
       <renderer-type>javax.faces.ViewRoot</renderer-type>
       <renderer-class>org.ajax4jsf.portlet.renderkit.portlet.PortletAjaxViewRootRenderer</renderer-class>
       </renderer>
       </render-kit>
       <application>
       <view-handler>
       org.ajax4jsf.portlet.application.PortletViewHandler
       </view-handler>
       <state-manager>
       org.ajax4jsf.portlet.application.PortalStateManager
       </state-manager>
       </application>
       <factory>
       <faces-context-factory>
       org.ajax4jsf.portlet.context.FacesContextFactoryImpl
       </faces-context-factory>
       </factory>
      </faces-config>
      


      My questions to the faces-config.xml are:
      - Do I have to prefix the from-view-id with a slash, like /start.xhtml ?
      - Do I have to prefix the to-view-id with a slash, like /start.xhtml?
      - Do you think/know if the navigation part of the faces-config.xml could cause the ViewExpiredException?

      5. SearchBean.java: As of now, I just return the string "success" to test how things work. I've removed all other business logic.

      6. war file directory structure:
      - WEB-INF
       - faces-config.xml
       - portlet.xml
       - web.xml
      - start.xhtml


      7. Dependencies:
      jsf-api: 1.2_04-p02
      jsf-impl: 1.2_04-p02
      jsf-facelets: 1.1.14
      portlet-api: 1.0
      jsp-api: 2.1
      portletbridge-api: 3.1.4.CR4
      portletbridge-impl: 3.1.4.CR4
      richfaces-api: 3.1.4.CR4
      richfaces-impl: 3.1.4.CR4
      richfaces-ui: 3.1.4.CR4