title: primefaces datatable with ajax pagination recreates viewscoped bean
body: <p>I have a Primefaces datatable with pagination enabled (which I think it uses ajax requests when we move between pages clicking the links of the paginator).</p>
  
  <p>In every row I have a commandbutton for editing the row. The method action of this commandbutton sets a managed bean property to hide the datatable and to show the edit form. I do this by enclosing the datatable in a panelgroup, and the edit form in another one, and setting the rendered attribute of the panelgroups accordingly to the managed bean property.</p>
  
  <p>The managed bean is Viewscoped, and all the requests I have are non-ajax.</p>
  
  <p>When I click the edit commandbutton on a row of the 1st datatable page, everything works ok.</p>
  
  <p>But if I move to another datatable page using the paginator links, and then I click the edit commandbutton on any row of the page, it doesn't work, because the Viewscoped bean is created again (PostConstruct is triggered), and even I can see that the action method of the clicked commandbutton isn't executed.</p>
  
  <p>I think it has to do with the ajax requests of the paginator (I guess).</p>
  
  <p>Anybody knows how to make it work?</p>
  
  <p>Thank you.</p>
  
  <p>I put here the relevant code to understand better the situation.</p>
  
  <p>My view:</p>
  
  <pre><code>&lt;ui:composition template="/paginas/plantillas/plantilla.xhtml"&gt;
  
      &lt;ui:define name="contenido"&gt;
  
          &lt;h:panelGroup rendered="#{clienteController.pagina=='LISTA'}"&gt;
              &lt;p:messages globalOnly="true" layout="table" closable="true" /&gt;
              &lt;p:dataTable id="tablaClientes" value="#{clienteController.clientesLazyList}" var="cli"
                   dblClickSelect="TRUE"
                   selectionMode="single"
                   selection="#{clienteController.cliente}"
                   rowKey="#{cli.id}"
                   paginator="true" rows="10" rowsPerPageTemplate="5,10,15" paginatorPosition="bottom"
                   currentPageReportTemplate="Total filas: {totalRecords} (mostrando {startRecord} a {endRecord}) (Página {currentPage} de {totalPages})"
                   paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} Filas/página: {RowsPerPageDropdown}"
                   emptyMessage="#{clienteController.msjListaVacia}"
                   lazy="true"&gt;
  
                  &lt;p:column ...&gt; ... &lt;/p:column&gt;
                        ...
                  &lt;p:column headerText="Editar"&gt;
                       &lt;h:form&gt;
                       &lt;p:commandButton ajax="false" action="#{clienteController.editarAction(cli)}" title="Editar" icon="ui-icon-pencil" /&gt;
                       &lt;/h:form&gt;
                  &lt;/p:column&gt;
              &lt;/p:dataTable&gt;
          &lt;/h:panelGroup&gt;
  
          &lt;h:panelGroup rendered="#{clienteController.pagina=='FORM'}"&gt;
              &lt;p:messages globalOnly="true" layout="table" closable="true" /&gt;
              &lt;h:form id="formCliente"&gt;
                      ...
                      ...
              &lt;/h:form&gt;
          &lt;/h:panelGroup&gt;
  
      &lt;/ui:define&gt;
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>My managed bean:</p>
  
  <pre><code>@ManagedBean(name="clienteController")
  @ViewScoped
  public class ClienteController extends BaseController {
  
      ...
  
      public ClienteController() {
          log.info("Constructor ClienteController");
      }
  
      @PostConstruct
      public void cargarAtributos() {
          ...
          this.pagina = TipoPagina.LISTA;
          log.info("PostConstruct ClienteController");
      }
  
      // Getters y Setters
      ...
  
      // EVENTO: Pulsar el enlace "editar" de la pantalla "lista"
      public String editarAction (Cliente c) {
          log.info("Método editarAction");
          ...
          this.pagina = TipoPagina.FORM;
          return null;
      }
  
      ...
  }
  </code></pre>