p:dataTable 删除行后不更新 [英] p:dataTable not updating after deleting row

查看:68
本文介绍了p:dataTable 删除行后不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了这个主题并尝试了所有的建议,但是我似乎无法得到一个看起来很简单的东西.

I have searched this topic and tried all the suggestions, however I just cannot seem to get what seems to be a very simple thing to work.

我有一个 PrimeFaces 3.4 <p:dataTable> 数据从我的支持 bean 中的 List 填充. 在每一行的一列中.我只是想实现一个简单的数据表的删除和刷新.然而,尽管从 List 对象中删除了元素,但数据表不会刷新.

I have a PrimeFaces 3.4 <p:dataTable> with data populated from a List in my backing bean and with a <p:commandLink> in one of the columns for every row. I am just trying to implement a simple delete and refresh of the data table. However although the element is removed from the List object, the data table does not refresh.

Bean(视图范围):

Bean (view scoped):

public void deleteRow(rowType row){
    this.tableDataList.remove(row);
}

查看:

<h:form id="form">
    <p:dataTable id="dt" var="dt" value=#{managedBean.tableDataList}
                 rowKey="#{dt.id}" selection="#{managedBean.selectedRow}"
                 selectionMode="single">
       <p:column><h:outputText value="#{dt.field1}"/></p:column>
       <p:column><h:outputText value="#{dt.field2}"/></p:column>
       <p:column><h:outputText value="#{dt.field3}"/></p:column>

       <p:column width="60">
          <p:commandLink id="deleteCl"
                         value="Delete"
                         actionListener="#{managedBean.deleteRow(dt)}"
                         update=":form:dt"
                         />
       </p:column>
</h:form>

据我所知,PrimeFaces 3.4 中的数据表应该能够通过子组件(例如命令链接)进行更新,但我无法使其正常工作.我实现了一个阶段监听器,所以我可以看到在渲染响应阶段之前没有验证或其他错误,但是数据表继续显示已删除的行,除非我刷新浏览器窗口,然后它会消失.

From what I can see, a data table in PrimeFaces 3.4 should be able to be updated via a child component such as a command link, but I just can't get it to work. I have a phase listener implemented so I can see that there are no validation or other errors before the render response phase, but the data table continues to display the deleted row unless I refresh the browser window, then it will disappear.

如果我在命令链接中设置 ajax="false" 就可以了,但是整个页面会被不必要地更新.

It works if I set ajax="false" in the command link, but then the entire page is updated unnecessarily.

我试过了:

  • actionactionListener
  • 之间切换
  • 以各种组合方式对命令链接属性进行以下更改:
    • process="@this"
    • update="@this"
    • update="@form"

    令人讨厌的是,我有一个带有命令链接的类似表,其中每个链接都会打开一个对话框窗口,其中包含另一个数据表,其中填充了基于最初单击的行检索的数据.在同一页面上完美运行.啊!

    The annoying thing is that I have a similar table with a command link where each link opens up a dialog window containing another data table that is populated with data retrieved based upon the row that was initially clicked. Works perfectly on the same page. Agh!

    推荐答案

    尝试从中对一些要点进行建模,看看是否对您有所帮助.

    Try modeling some points from this to see if it helps you.

          <h:outputText escape="false" value="#{message.noCompaniesFound}" rendered="#{companyController.companyModel.rowCount == 0}"/>
                <h:panelGroup rendered="#{companyController.companyModel.rowCount > 0}">
                    <p:commandButton id="addButton" value="#{message.newCompany}" oncomplete="companyDialog.show()" icon="ui-icon-plus" title="#{message.addCompany}" rendered="#{loginController.privileges.contains(bundle.SuperUser)}"/>  
    
                    <p:dataTable id="companyList" var="company" widgetVar="companyTable" value="#{companyController.companyModel}" rowKey="#{company.name}" selection="#{companyController.selectedCompany}" selectionMode="single"
                                 paginator="true" rows="10"
                                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                 rowsPerPageTemplate="5,10,15,20,50,100">
    
                        <p:ajax event="rowEdit" update="@this" listener="#{companyController.saveCompany(company)}">
                            <f:param name="company" value="#{company}"/>
                        </p:ajax>      
    
                        <f:facet name="header">
                            <p:outputPanel>
                                <h:outputText value="#{message.search}: "/>
                                <p:inputText id="globalFilter" onkeyup="companyTable.filter()"/>
                            </p:outputPanel>
                        </f:facet>
    
                        <p:column id="name" headerText="#{message.name}" filterBy="#{company.name}" filterMatchMode="contains" filterStyle="display: none;">
                            <h:outputText value="#{company.name}"/>
                        </p:column>
    
                        <p:column headerText="#{message.editOptions}" style="width:10px;">
                            <p:commandButton id="editButton" update=":companyForm" oncomplete="editDialog.show()" icon="ui-icon-pencil" title="#{message.edit}">                                
                                <f:setPropertyActionListener value="#{company}" target="#{companyController.selectedCompany}"/>
                            </p:commandButton>
                            <p:commandButton id="deleteButton" update=":companyForm" oncomplete="confirmation.show()" icon="ui-icon-trash" title="#{message.delete}">                                
                                <f:setPropertyActionListener value="#{company}" target="#{companyController.selectedCompany}"/>
                            </p:commandButton>
                        </p:column>
                        <f:facet name="footer">
                        </f:facet>
                    </p:dataTable>
                </h:panelGroup>
    
    
                <p:confirmDialog id="confirmDialog" message="#{message.sureYouWantToDelete} #{companyController.selectedCompany.name} ?" severity="alert" widgetVar="confirmation">
                    <p:commandButton id="confirm" value="#{message.yes}" onclick="confirmation.hide()" actionListener="#{companyController.deleteCompany}" update="companyForm" />
                    <p:commandButton id="decline" value="#{message.no}" onclick="confirmation.hide()"/>    
                </p:confirmDialog>
    

    这篇关于p:dataTable 删除行后不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆