grimmel
grimmel

Reputation: 103

p:dataTable not updating after deleting row

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.

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 (view scoped):

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

View:

<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>

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.

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

I have tried:

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!

Upvotes: 0

Views: 5337

Answers (1)

Ronald91
Ronald91

Reputation: 1776

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>

Upvotes: 1

Related Questions