primefaces更新数据表行

时间:2014-08-15 07:00:12

标签: jsf jsf-2 primefaces

我有p:dataTable并在使用p:dialog点击两次数据表行时显示<p:ajax event="rowDblselect" immediate="true" process="@this" oncomplete="PF('tgelPrintForm').show();" update=":form:modalDialog" />。在对话框中,我有一个chation,其中包含一个选定的数据表行单元格。问题是我不知道如何使用新值更新该单元格。我想我需要一些primefaces配置和primefaces将自动更新,但由于我是JSF和Primefaces的新手,我解决这个问题是个问题。这是我的代码。

数据表:

<p:dataTable styleClass="myDataGrid" id="tbl2" var="domesticTransactions" value="#{domesticTransferGridManagedBean.domesticTransactions}"
    paginator="true" rows="15" rowKey="#{domesticTransactions.id}" scrollable="true" scrollHeight="280"
    paginatorPosition="bottom"
    paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
    selection="#{domesticTransferGridManagedBean.selectedDomesticTransfer}" selectionMode="single">
    <p:ajax event="rowDblselect" immediate="true" process="@this" oncomplete="PF('tgelPrintForm').show();" update=":form:modalDialog" />

对话框:

 <p:dialog dynamic="true" id="modalDialog" appendToBody="@{body}" widgetVar="tgelPrintForm" 
              modal="true" height="400" width="750px" resizable="false" closeOnEscape="true"> <c:choose>
                <c:when test="#{domesticTransferGridManagedBean.selectedDomesticTransfer.status eq 'WAITING_FOR_FIRST_SIGNER_SIGN'}">
                      <p:commandButton actionListener="#{domesticTransferGridManagedBean.addFirstSignerSignToDomesticTransaction}" 
                                       id="domesticTransferFirstSignerSign"
                                       value="#{msg['label.FirstSignerSignature']}" 
                                       styleClass="myButton"
                                       process="@this"
                                       update="status"
                                       oncomplete="PF('tgelPrintForm').hide()">
                      </p:commandButton>

托管bean方法:

    private DomesticTransfer selectedDomesticTransfer;

    public void addFirstSignerSignToDomesticTransaction() {
    try {
        long domesticTransferId = selectedDomesticTransfer.getId();
        assert domesticTransferId > 0;
        selectedDomesticTransfer = domesticTransferService.addFirstSignToDomesticTransfer(domesticTransferId);
    } catch(Exception e) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, e.getMessage(), null));
    }
}

2 个答案:

答案 0 :(得分:1)

您的对话框应该update包含所选条目的表格tbl2

<p:commandButton actionListener="#{domesticTransferGridManagedBean.addFirstSignerSignToDomesticTransaction}" 
                 id="domesticTransferFirstSignerSign"
                 value="#{msg['label.FirstSignerSignature']}" 
                 styleClass="myButton"
                 process="@this"
                 update="status tbl2"
                 oncomplete="PF('tgelPrintForm').hide()">

答案 1 :(得分:1)

您只需要更新数据表,将数据表ID传递给命令按钮中的更新参数。

<p:commandButton actionListener="#{domesticTransferGridManagedBean.addFirstSignerSignToDomesticTransaction}" 
                                       id="domesticTransferFirstSignerSign"
                                       value="#{msg['label.FirstSignerSignature']}" 
                                       styleClass="myButton"
                                       process="@this"
                                       update="status tbl2"
                                       oncomplete="PF('tgelPrintForm').hide()">
</p:commandButton>

根据表格和对话框的位置,您可能需要传递数据表的绝对ID:

update="status :tbl2"update="status form:tbl2"等。