title: JSF 2.2 ViewScoped bean behaving as if it were SessionScoped bean in WebSphere Portal
body: <p>I'm working on a project, which uses JSF 2.2 in a "WebSphere Portal" environment.</p>
  
  <p>I am having strange behavior with ViewScoped beans.</p>
  
  <p>Suppose I have two pages in my Portal, one called "A" and one called "B".</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>WebSphere Portal 9.0</p>
  
  <p>JSF 2.2</p>
  
  <h3>web.xml</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
      &lt;display-name&gt;GSRE-GestaoUsuarios-Portlet&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;description&gt;
              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.&lt;/description&gt;
          &lt;param-name&gt;com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;com.ibm.faces20.portlet.httpbridge.PortletRequestAttributesListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;enabled&gt;true&lt;/enabled&gt;
          &lt;async-supported&gt;false&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <h3>faces-config.xml</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
    &lt;application&gt;
      &lt;view-handler&gt;com.ibm.faces20.portlet.FaceletPortletViewHandler&lt;/view-handler&gt;
      &lt;el-resolver&gt;com.ibm.faces20.portlet.PortletELResolver&lt;/el-resolver&gt;
      &lt;resource-handler&gt;com.ibm.faces20.portlet.httpbridge.PortletResourceHandler&lt;/resource-handler&gt;
    &lt;/application&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletActionURL&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletActionURL&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletResourceURL&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletResourceURL&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletRenderURL&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletRenderURL&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletParam&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletParam&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletProperty&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletProperty&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;component&gt;
      &lt;component-type&gt;com.ibm.faces20.portlet.component.PortletNameSpace&lt;/component-type&gt;
      &lt;component-class&gt;com.ibm.faces20.portlet.component.PortletNameSpace&lt;/component-class&gt;
    &lt;/component&gt;
    &lt;render-kit&gt;
      &lt;renderer&gt;
        &lt;component-family&gt;javax.faces.Output&lt;/component-family&gt;
        &lt;renderer-type&gt;com.ibm.faces20.portlet.tag.render.ActionURLTagRender&lt;/renderer-type&gt;
        &lt;renderer-class&gt;com.ibm.faces20.portlet.tag.render.ActionURLTagRender&lt;/renderer-class&gt;
      &lt;/renderer&gt;
    &lt;/render-kit&gt;
    &lt;render-kit&gt;
      &lt;renderer&gt;
        &lt;component-family&gt;javax.faces.Output&lt;/component-family&gt;
        &lt;renderer-type&gt;com.ibm.faces20.portlet.tag.render.ResourceURLTagRender&lt;/renderer-type&gt;
        &lt;renderer-class&gt;com.ibm.faces20.portlet.tag.render.ResourceURLTagRender&lt;/renderer-class&gt;
      &lt;/renderer&gt;
    &lt;/render-kit&gt;
    &lt;render-kit&gt;
      &lt;renderer&gt;
        &lt;component-family&gt;javax.faces.Output&lt;/component-family&gt;
        &lt;renderer-type&gt;com.ibm.faces20.portlet.tag.render.RenderURLTagRender&lt;/renderer-type&gt;
        &lt;renderer-class&gt;com.ibm.faces20.portlet.tag.render.RenderURLTagRender&lt;/renderer-class&gt;
      &lt;/renderer&gt;
    &lt;/render-kit&gt;
    &lt;render-kit&gt;
      &lt;renderer&gt;
        &lt;component-family&gt;javax.faces.Output&lt;/component-family&gt;
        &lt;renderer-type&gt;com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender&lt;/renderer-type&gt;
        &lt;renderer-class&gt;com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender&lt;/renderer-class&gt;
      &lt;/renderer&gt;
    &lt;/render-kit&gt;
  &lt;/faces-config&gt;
  </code></pre>
  
  <p>How to make the @ViewScope scope work as expected, ie both page refresh and browser refresh destroy and build the bean.</p>