好吧,我有一个在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");
}
就是这样,提前谢谢。