JSF 2.2 ViewScoped bean behaving as if it were SessionScoped bean in WebSphere Portal

I'm working on a project, which uses JSF 2.2 in a "WebSphere Portal" environment.

I am having strange behavior with ViewScoped beans.

Suppose I have two pages in my Portal, one called "A" and one called "B".

On my "A" page there is a portlet that has a screen with a list of Ajax paging items. Suppose I click to go to page 2 in this list of items and I navigate to the "B" page in the Portal.

The expected behavior of a ViewScoped bean is that when we leave the page the bean is destroyed, and when we return the bean is constructed, restarting all the data, that is, losing the state.

However, when I navigate to page "A" again, the current page of the portlet screen pagination is at 2, that is, kept the state, even though I navigated to another page.

WebSphere Portal 9.0

JSF 2.2

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.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-app_3_0.xsd">

    <display-name>GSRE-GestaoUsuarios-Portlet</display-name>

    <context-param>
        <description>
            Load JSF runtime when the application server starts up. If this parameter is set to false or removed,
            JSF runtime will be loaded and initialized when the first JSF request is processed.
            This may disable custom JSF extensions, such as factories defined in the project.</description>
        <param-name>com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP</param-name>
        <param-value>true</param-value>
    </context-param>

    <listener>
        <listener-class>com.ibm.faces20.portlet.httpbridge.PortletRequestAttributesListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <enabled>true</enabled>
        <async-supported>false</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

</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.ibm.faces20.portlet.FaceletPortletViewHandler</view-handler>
    <el-resolver>com.ibm.faces20.portlet.PortletELResolver</el-resolver>
    <resource-handler>com.ibm.faces20.portlet.httpbridge.PortletResourceHandler</resource-handler>
  </application>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletActionURL</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletActionURL</component-class>
  </component>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletResourceURL</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletResourceURL</component-class>
  </component>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletRenderURL</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletRenderURL</component-class>
  </component>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletParam</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletParam</component-class>
  </component>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletProperty</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletProperty</component-class>
  </component>
  <component>
    <component-type>com.ibm.faces20.portlet.component.PortletNameSpace</component-type>
    <component-class>com.ibm.faces20.portlet.component.PortletNameSpace</component-class>
  </component>
  <render-kit>
    <renderer>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-type>
      <renderer-class>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-class>
    </renderer>
  </render-kit>
  <render-kit>
    <renderer>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-type>
      <renderer-class>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-class>
    </renderer>
  </render-kit>
  <render-kit>
    <renderer>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-type>
      <renderer-class>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-class>
    </renderer>
  </render-kit>
  <render-kit>
    <renderer>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-type>
      <renderer-class>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-class>
    </renderer>
  </render-kit>
</faces-config>

How to make the @ViewScope scope work as expected, ie both page refresh and browser refresh destroy and build the bean.

Upvotes: 0

Views: 256

Answers (0)

Related Questions