好吧,我有一个在primefaces上使用rowExpansion的嵌套数据表,在子数据表的每一行中我都有一个编辑内容的按钮,问题是当我在父数据表上有多个出现时,出现在子数据上表松散与对象的连接,所以当我点击按钮编辑时引用是错误的。
表:
p:dataTable value="#{LiquidacaoControl.liquidacoes}" var="liquidacao" id="tbl_liquidacao" emptyMessage="Nenhuma liquidação adicionada" rendered="#{LiquidacaoControl.empenho != null}">
<f:facet name="header">
<h:outputText value="Tabela de Liquidações" />
</f:facet>
<p:ajax event="rowToggle" listener="#{LiquidacaoControl.onRowExpandir}" update="tbl_documentoFiscal" />
<p:column>
<p:rowToggler />
</p:column>
<p:column headerText="Data">
<h:outputText value="#{liquidacao.data}">
<f:convertDateTime pattern="d/M/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Valor da liquidação">
<h:outputText value="#{liquidacao.totalValorLiquidacao}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
<p:column headerText="Valor retido">
<h:outputText value="#{liquidacao.valorTotalRetido}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
<p:column headerText="tipo">
<h:outputText value="#{liquidacao.tipo.descricao}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
<p:column>
<p:commandButton icon="ui-icon-pencil" oncomplete="liquidacao_dialog.show();" update=":formCorpo:liquidacaoForm">
<f:setPropertyActionListener value="#{liquidacao}" target="#{LiquidacaoControl.liquidacao}" />
</p:commandButton>
<p:commandButton icon="ui-icon ui-icon-trash" update=":formCorpo:tbl_liquidacao" actionListener="#{LiquidacaoControl.excluirLiquidacao}">
<f:attribute name="liquidacao" value="#{liquidacao}"></f:attribute>
</p:commandButton>
<p:commandButton value="Adicionar documento fiscal" update=":formCorpo:documentoFiscalForm" action="#{LiquidacaoControl.novoDocumentoFiscal}">
<f:setPropertyActionListener value="#{liquidacao}" target="#{LiquidacaoControl.liquidacao}" />
</p:commandButton>
</p:column>
<p:rowExpansion>
<p:dataTable value="#{LiquidacaoControl.documentosFiscais}" rowKey="#{documentoFiscal.hash}" selectionMode="single" var="documentoFiscal" id="tbl_documentoFiscal" emptyMessage="Nenhum Documento Fiscal">
<p:ajax event="rowSelect" update=":formCorpo:tbl_retencao" oncomplete="tbl_retencao_dialog.show();" listener="#{LiquidacaoControl.onRowSelection}" />
<f:facet name="header">
<h:outputText value="Tabela de documentos fiscais" />
</f:facet>
<p:column headerText="N° Doc">
<h:outputText value="#{documentoFiscal.numero}">
</h:outputText>
</p:column>
<p:column headerText="Chave NF-e">
<h:outputText value="#{documentoFiscal.chaveAcesso}">
</h:outputText>
</p:column>
<p:column headerText="Data emissão">
<h:outputText value="#{documentoFiscal.dataEmissao}">
<f:convertDateTime pattern="d/M/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Valor">
<h:outputText value="#{documentoFiscal.valor}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
<p:column headerText="Valor retido">
<h:outputText value="#{documentoFiscal.valorTotalRetido}">
<f:convertNumber currencySymbol="R$" type="currency" />
</h:outputText>
</p:column>
<p:column>
<p:commandButton icon="ui-icon-pencil" update=":formCorpo:documentoFiscalForm" actionListener="#{LiquidacaoControl.editarDocumentoFiscal}">
<f:attribute name="documentoFiscal" value="#{documentoFiscal}"></f:attribute>
</p:commandButton>
<p:commandButton icon="ui-icon ui-icon-trash" update=":formCorpo:tbl_liquidacao" actionListener="#{LiquidacaoControl.excluirDocumentoFiscal}">
<f:attribute name="documentoFiscal" value="#{documentoFiscal}"></f:attribute>
</p:commandButton>
<p:commandButton value="Adicionar retenção" onclick="retencao_dialog.show();" actionListener="#{LiquidacaoControl.novaRetencao}" update=":formCorpo:retencaoForm">
<f:setPropertyActionListener value="#{documentoFiscal}" target="#{LiquidacaoControl.documentoFiscal}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
方法:
public void editarDocumentoFiscal(ActionEvent event) {
DocumentoFiscal pDocumentoFiscal = (DocumentoFiscal) event.getComponent().getAttributes().get("documentoFiscal");
setDocumentoFiscal(pDocumentoFiscal);
RequestContext.getCurrentInstance().execute("documentoFiscal_dialog.show()");
}
public void excluirDocumentoFiscal(ActionEvent event) {
DocumentoFiscal pDocumentoFiscal = (DocumentoFiscal) event.getComponent().getAttributes().get("documentoFiscal");
encontrarPaiDocumentoFiscal(pDocumentoFiscal);
liquidacao.getDocumentosFiscais().remove(pDocumentoFiscal);
}
public void onRowExpandir(ToggleEvent event) {
documentosFiscais = new DocumentoFiscalModel(((Liquidacao) event.getData()).getDocumentosFiscais());
RequestContext.getCurrentInstance().update("formCorpo:tbl_documentoFiscal");
}
这是事先感谢。
答案 0 :(得分:0)
这是jsf中客户端状态的问题,它适用于我的
web.xml add
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>