Reputation: 4754
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).
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.
The managed bean is Viewscoped, and all the requests I have are non-ajax.
When I click the edit commandbutton on a row of the 1st datatable page, everything works ok.
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.
I think it has to do with the ajax requests of the paginator (I guess).
Anybody knows how to make it work?
Thank you.
I put here the relevant code to understand better the situation.
My view:
<ui:composition template="/paginas/plantillas/plantilla.xhtml">
<ui:define name="contenido">
<h:panelGroup rendered="#{clienteController.pagina=='LISTA'}">
<p:messages globalOnly="true" layout="table" closable="true" />
<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">
<p:column ...> ... </p:column>
...
<p:column headerText="Editar">
<h:form>
<p:commandButton ajax="false" action="#{clienteController.editarAction(cli)}" title="Editar" icon="ui-icon-pencil" />
</h:form>
</p:column>
</p:dataTable>
</h:panelGroup>
<h:panelGroup rendered="#{clienteController.pagina=='FORM'}">
<p:messages globalOnly="true" layout="table" closable="true" />
<h:form id="formCliente">
...
...
</h:form>
</h:panelGroup>
</ui:define>
</ui:composition>
My managed bean:
@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;
}
...
}
Upvotes: 3
Views: 1352
Reputation: 121
Pity but there seems to be a problem with view scoped beans and primefaces datatable...but it is not so primefaces related but more JSF staff propably. As many posts have issued, there is a problem with some a method called binding used in Jsf that makes the recreation of the view bean temporarily. i dont thing there is an easy way to bypass it. unless primafaces finds a way with an update in their components when used in view scope.
Upvotes: 2