我有一個啓用分頁的Primefaces數據表(我認爲它使用Ajax請求,當我們在點擊頁面鏈接的頁面之間移動時)。primefaces datatable與ajax分頁重新創建viewscoped bean
在每一行我都有一個用於編輯行的命令按鈕。此命令按鈕的方法操作設置託管bean屬性以隱藏數據表並顯示編輯表單。我通過將數據表放在面板組中,將編輯表單放在另一個表單中,並相應地將面板組的渲染屬性設置爲託管bean屬性。
託管bean是Viewscoped,並且我擁有的所有請求都是非ajax。
當我點擊第一個數據表頁的一行上的編輯commandbutton,一切正常。
但是,如果我使用paginator鏈接移動到另一個數據表頁面,然後單擊頁面任意行上的編輯commandbutton,它將不起作用,因爲Viewscoped bean會再次創建(PostConstruct被觸發),甚至我可以看到單擊的命令按鈕的操作方法沒有執行。
我認爲它與paginator的ajax請求(我猜)有關。
任何人都知道如何使它工作?
謝謝。
我把這裏的相關代碼,以更好地瞭解情況。
我的觀點:
<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>
我管理的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;
}
...
}
你設法解決這個問題嗎? – adranale