简体   繁体   English

<p:ajax event=“rowEditCancel”>在我的primeface的数据表上不更新数据表

[英]<p:ajax event=“rowEditCancel”> on my primeface's datatable don't update datatable

I'm using Primefaces' p:dataTable to display an editable table and I'm using p:rowEditor to add or delete rows, when adding a row I add an object to the datalist and update the datatable, this works fine, but when I cancel edit I delete the added object to the datatable, the listener is fired but it doesn't update the datatable, any suggestions please. 我正在使用Primefaces的p:dataTable来显示一个可编辑的表,我正在使用p:rowEditor来添加或删除行,当添加一行时我将一个对象添加到datalist并更新数据表,这很好,但是当我取消编辑我删除了添加到datatable的对象,触发器被触发但它没有更新数据表,请提出任何建议。 here is the .xhtml: 这是.xhtml:

<h:form id="Users">
            <p:dataTable id="datalist"
                    value="#{beanController.listusr}" var="item"
                    selectionMode="single" editable="true"
                    styleClass="datalistdisplayusr"
                    selection="#{beanController.selectedusr}"
                    rowKey="#{item.usrId}"
                    paginator="true" rows="5" rowsPerPageTemplate="5,10,15">
                    <f:facet name="header">
                        <p:commandButton id="newusrButton" icon="ui-icon-plus"
                            value="Create"
                            actionListener="#{beanController.createusr}"
                            update=":Users:datalist" 
                            oncomplete="$('.datalistdisplayusr .ui-datatable-data .ui-row-editor .ui-icon-pencil').first().click();"
                            />
                    </f:facet>

                    <p:ajax event="rowEdit"
                        listener="#{beanController.saveusr}"
                        update=":Users:datalist" />
                    <p:ajax event="rowEditCancel"
                        listener="#{beanController.onCancel}"
                        update=":Users:datalist" />

                    <p:column style="width:6%">
                        <p:rowEditor />
                    </p:column>
                    <p:column >
                        <f:facet name="header">
                            <h:outputText value="Id" />
                        </f:facet>

                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.usrId}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText id="Id" value="#{item.usrId}"   />
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                    <p:column >
                        <f:facet name="header">
                            <h:outputText value="First Name" />
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.usrName}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText id="FirstName" value="#{item.usrName}"  />
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                    <p:column >
                        <f:facet name="header">
                            <h:outputText value="Last Name" />
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.usrSurName}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText id="SurName" value="#{item.usrSurName}" />
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                </p:dataTable>

And here is the save method. 这是保存方法。 Till now every thing works fine I have the object added and the datatable updated: 直到现在每件事都运行正常我添加了对象并更新了数据表:

public void createusr(ActionEvent event) {
        UserDTO usr = new UserDTO();
        listusr.add(0, usr);            
}

and here is the onCancel listener: 这是onCancel监听器:

public void onCancel(RowEditEvent event){ 
         list.remove(0);
}

The listener is fired and the object is deleted by I the datatable is not updated and instead of deleting the row I have the second row duplicated. 触发器被触发并且对象被删除,我没有更新数据表,而是删除了第二行重复的行。

I found a workaround here: PrimeFaces DataTable RowEditor updating cell elements on RowEditInit, but not on RowEdit or RowEditCancel 我在这里找到了一个解决方法: PrimeFaces DataTable RowEditor更新RowEditInit上的单元格元素,但不更新RowEdit或RowEditCancel

Basically, it consist in adding ap:remoteCommand in the oncomplete attribute of p:ajax: 基本上,它包括在p:ajax的oncomplete属性中添加ap:remoteCommand:

<p:ajax oncomplete="updateDataTable()" event="rowEditCancel" listener="#{beanView.onRowEventCancelMethod}" global="false" process="@this"/>

and putting the p:remoteCommand outside the dataTable: 并将p:remoteCommand放在dataTable之外:

<p:remoteCommand name="updateDataTable" update="myDataTableId"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM