title: ViewScoped bean is recreated everytime I click on commandButton in my dataTable
body: <p>Im using primefaces version 3.1.1, Mojarra 2.1.3, Netbeans 7.0.1, Glassfish Server 3.1.</p>
  
  <p>My test application is using a facelet template with top, left, content, right and bottom layout with raw divs and css. After user logs in with container managed jdbcrealm, they will be presented with the main index.html which use the said template. </p>
  
  <p>I put a navigation menu on the left panel which will subsequently update center panel content with ajax upon clicking menuitem. The center panel will be updated dynamically in <code>&lt;ui:include&gt;</code> by using sessionScoped <code>NavigationBean</code>.</p>
  
  <p>In one of the page <code>clientList.xhtml</code>, I put a <code>&lt;p:dataTable&gt;</code> with a button to view the detail by popping up a <code>&lt;p:dialog&gt;</code>. Im using a viewCoped bean to hold the data list displayed on the dataTable.  </p>
  
  <p>The problem is, when I click on the button to select a row in the last colum of every row, the dialog does not appear at all, and my <code>p:ajaxStatus</code> gif image kept on rolling unendingly. When I debug the program with netbeans, I notice the constructor is called again and the previous instance is gone after clicking the button.</p>
  
  <p>This is my <code>index.xhtml</code> using facelets template.</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"&gt;
  &lt;ui:composition template="/BySalesAutomationTemplate.xhtml"&gt;
      &lt;ui:define name="title"&gt;
          &lt;h:outputText value="Facelet Index Page"&gt;&lt;/h:outputText&gt;
      &lt;/ui:define&gt;
      &lt;ui:define name="top"&gt;
          TOP
      &lt;/ui:define&gt;
      &lt;ui:define name="left"&gt;
          &lt;ui:include src="users/menu#{request.isUserInRole('ADMIN') ? 'Admin' : 'User'}.xhtml" /&gt;
      &lt;/ui:define&gt;
      &lt;ui:define name="right"&gt;
          &lt;h:outputText value="Cuba2 daan"&gt;&lt;/h:outputText&gt;
      &lt;/ui:define&gt;
      &lt;ui:define name="maincontent"&gt;
          &lt;c:if test="#{navigationBean.page!=null}"&gt;
              &lt;ui:include src="#{navigationBean.page}.xhtml" /&gt;
          &lt;/c:if&gt;
      &lt;/ui:define&gt; 
      &lt;ui:define name="bottom"&gt;
          &lt;center&gt;2012&lt;/center&gt; 
      &lt;/ui:define&gt;
    &lt;/ui:composition&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the <code>clientList.xhtml</code> page which is displayed in the center panel of my index.xhtml upon clicking a link on the menu in the left panel.</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"&gt;
  &lt;h:head&gt;
      &lt;title&gt;Client Listing&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;p&gt;Client List&lt;/p&gt;
      &lt;h:form&gt;
          &lt;h:commandButton action="#{authBackingBean.logout}" value="Logout" /&gt;
      &lt;/h:form&gt;
      &lt;f:view&gt;
          &lt;h:form id="formdetail" prependId="false"&gt;
              &lt;p:ajaxStatus&gt;
                  &lt;f:facet name="start"&gt;
                      &lt;h:graphicImage value="images/loading.gif" /&gt;
                  &lt;/f:facet&gt;
                  &lt;f:facet name="complete"&gt;
                      &lt;h:outputText value="" /&gt;
                  &lt;/f:facet&gt;
              &lt;/p:ajaxStatus&gt;
              &lt;p:growl id="growl" showDetail="true"/&gt;
              &lt;p:dataTable id="dtClientList" value="#{saClientController.lazyModel}" rowsPerPageTemplate="10,20,30,50" 
                           paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
                           paginatorAlwaysVisible="false" var="item" paginator="true" rows="10"&gt;
                  &lt;f:facet name="header"&gt;
                      &lt;h:outputText value="Client List"/&gt;
                  &lt;/f:facet&gt;
                  &lt;p:column filterBy="#{item.idSaClient}"&gt;
                      &lt;f:facet name="header"&gt;
                          &lt;h:outputText value="IdSaClient"/&gt;
                      &lt;/f:facet&gt;
                      &lt;p:commandLink action="#{saClientController.showDetails(item)}" value="#{item.idSaClient}" target=":maincontent"/&gt;                        
                  &lt;/p:column&gt;
                  &lt;p:column filterBy="#{item.saClientName}"&gt;
                      &lt;f:facet name="header"&gt;
                          &lt;h:outputText value="saClientName"/&gt;
                      &lt;/f:facet&gt;
                      &lt;h:outputText value="#{item.saClientName}"/&gt;
                  &lt;/p:column&gt;
                  &lt;p:column filterBy="#{#item.saClientAddress}"&gt;
                      &lt;f:facet name="header"&gt;
                          &lt;h:outputText value="SaClientAddress"/&gt;
                      &lt;/f:facet&gt;
                      &lt;h:outputText value="#{item.saClientAddress}"/&gt;
                  &lt;/p:column&gt;
                  &lt;p:column style="width:40px"&gt;  
                      &lt;h:panelGrid columns="3" styleClass="actions" cellpadding="2"&gt;  
                          &lt;p:commandButton id="selectButton" update=":formdetail:display" oncomplete="clientDialog.show()" icon="ui-icon-search" title="View"&gt;                                  
                              &lt;f:setPropertyActionListener value="#{item}" target="#{saClientController.selectedSaClient}" /&gt;  
                          &lt;/p:commandButton&gt;  
                      &lt;/h:panelGrid&gt;  
                  &lt;/p:column&gt;  
                  &lt;f:facet name="footer"&gt;
                      &lt;h:outputText value="Client List"/&gt;
                  &lt;/f:facet&gt;
              &lt;/p:dataTable&gt;                      
          &lt;/h:form&gt;
  
          &lt;p:dialog id="clientDialog" header="Client Detail" widgetVar="clientDialog" resizable="false" showEffect="explode" hideEffect="explode"&gt;
              &lt;h:panelGrid id="display" columns="2" cellpadding="4"&gt; 
                   &lt;f:facet name="header"&gt; 
                       &lt;h:outputText value="Selected Row" /&gt;
                   &lt;/f:facet&gt; 
                   &lt;h:outputText value="ID" /&gt;
                   &lt;h:outputText value="#{saClientcontroller.selectedSaClient.idSaClient}" /&gt;
                   &lt;h:outputText value="NAME:" /&gt; 
                   &lt;h:outputText value="#{saClientcontroller.selectedSaClient.saClientName}" /&gt; 
                   &lt;h:outputText value="DESCRIPTION:" /&gt;  
                   &lt;h:outputText value="#{saClientcontroller.selectedSaClient.saClientAddress}" /&gt;  
               &lt;/h:panelGrid&gt;
          &lt;/p:dialog&gt;                   
  
      &lt;/f:view&gt;
    &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my Backing Bean.</p>
  
  <pre><code>public class SaClientController implements Serializable {
  
      @EJB
      private SaClientFacade saClientFacade;
      private SaClient selectedSaClient;
      private LazyDataModel&lt;SaClient&gt; lazyModel;
      private List&lt;SaClient&gt; saclients;
  
      /** Creates a new instance of SaClientController */
      public SaClientController() {
      }
  
      @PostConstruct
      public void Init() {
          saclients = saClientFacade.Retrieve();
          lazyModel = new LazyDataModelImp(saclients);
      }
  
      public LazyDataModel&lt;SaClient&gt; getLazyModel() {
          return lazyModel;
      }
  
      public List&lt;SaClient&gt; getClients() {
          return saClientFacade.Retrieve();
      }
  
      public SaClient getDetails() {
          return selectedSaClient;
      }
  
      public String showDetails(SaClient selectedSaClient) {
          this.selectedSaClient = selectedSaClient;
          return "DETAILS";
      }
  
      public String update() {
          System.out.println("###UPDATE###");
          selectedSaClient = saClientFacade.Update(selectedSaClient);
          return "SAVED";
      }
  
      public String list() {
          System.out.println("###LIST###");
          return "LIST";
      }
  
      public SaClient getSelectedSaClient() {
          return selectedSaClient;
      }
  
      public void setSelectedSaClient(SaClient selectedSaClient) {
          this.selectedSaClient = selectedSaClient;
      }
  
      public String dummyAction()
      {
          return null;
      }
  }
  </code></pre>
  
  <p>This is the <code>LazyModelImp</code> class</p>
  
  <pre><code>public class LazyDataModelImp extends LazyDataModel&lt;SaClient&gt; {
  
      private List &lt;SaClient&gt; datasource;
  
      public LazyDataModelImp(List&lt;SaClient&gt; datasource) {
          this.datasource = datasource;
      }
  
      @Override
      public SaClient getRowData(String rowKey) {
          for (SaClient saclient : datasource) {
              if (saclient.getIdSaClient().toString().equals(rowKey)) {
                  return saclient;
              }
          }
          return null;
      }
  
      @Override
      public Object getRowKey(SaClient saclient) {
          return saclient.getIdSaClient().toString();
      }
  
      @Override
      public List&lt;SaClient&gt; load(int first, int pageSize, String sortField, SortOrder sortOrder, Map&lt;String, String&gt; filters) {
          List&lt;SaClient&gt; data = new ArrayList&lt;SaClient&gt;();
          //filter        
          for (SaClient saclient : datasource) {
              boolean match = true;
              for (Iterator&lt;String&gt; it = filters.keySet().iterator(); it.hasNext();) {
                  try {                    
                      String filterProperty = it.next();
                      String filterValue = filters.get(filterProperty);
                      String fieldValue = String.valueOf(saclient.getFilterSortFieldValue(filterProperty));
                      if (filterValue == null || fieldValue.startsWith(filterValue.toUpperCase()) || fieldValue.startsWith(filterValue.toLowerCase())) {
                          match = true;
                      } else {
                          match = false;
                          break;
                      }
                  } catch (Exception e) {
                      match = false;
                  }
              }
              if (match) {
                  data.add(saclient);
              }
          }
          //rowCount
          int dataSize = data.size();
          this.setRowCount(dataSize);
          //paginate
          if (dataSize &gt; pageSize) {
              try {
                  return data.subList(first, first + pageSize);
              } catch (IndexOutOfBoundsException e) {
                 return data.subList(first, first + (dataSize % pageSize));
              }
          }
          else {
              return data;
          }
          //sort
          //if (sortField != null) {
          //    Collections.sort(data, new LazySorter(sortField, sortOrder));
          //}       
          //return data;
      }
  }
  </code></pre>
  
  <p>I've already disabled the partial state saving in <code>web.xml</code>.</p>
  
  <pre><code>&lt;context-param&gt; 
      &lt;param-name&gt;javax.faces.PARTIAL_STATE_SAVING&lt;/param-name&gt; 
      &lt;param-value&gt;false&lt;/param-value&gt; 
  &lt;/context-param&gt; 
  </code></pre>
  
  <p>The backingBean is reinitialized the first time I click on the view detail commandButton in the last column of the dataTable in <code>clienList.xhtml</code>. And the dialog does not display at all. But after pressing F5. The dialog can be displayed but without any content, the only thing displayed in the dialog is the label outputText but not the bean values, they are empty. Sorry for newbie question. I will be extremely glad if anyone could advise what im doing is wrong, and maybe a little advise on the navigation and whether my strategy of displaying everything in <code>index.xhtml</code> (so I only have 1 view id all the time which is <code>index.xhtml</code>, right?) is right. </p>