【问题标题】:primefaces update datatable rowsprimefaces 更新数据表行
【发布时间】:2014-10-08 22:53:21
【问题描述】:

当使用<p:ajax event="rowDblselect" immediate="true" process="@this" oncomplete="PF('tgelPrintForm').show();" update=":form:modalDialog" /> 两次单击数据表行时,我有p:dataTable 并显示p:dialog。在对话框中,我有一个按钮可以更改选定数据表行单元格之一的状态。问题是我不知道如何使用新值更新该单元格。我想我需要一些 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));
    }
}

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    您的对话框应该updatetbl2 也包含所选条目:

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

    【讨论】:

      【解决方案2】:

      您只需要更新您的数据表,将数据表 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"

      【讨论】:

        猜你喜欢
        • 2013-09-15
        • 2016-09-15
        • 2017-08-17
        • 2015-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-14
        相关资源
        最近更新 更多