Hunter
Hunter

Reputation: 890

<p:datatable/> not refreshing after deleting

I am using JSF and Primefaces in my web application.

I am using p:datatable id="jobEditTable" component of primefaces.

In this i have option of deleting some rows.

In datatable i have one delete button on clicking of that button i am showing a p:dialog id="deleteJob" Then i fill some resaon for deleting in p:dialog then i am clicking on one command link in p:dialog then it calls one action listener where i am clearing the list of data and creating again.

And onClick of that command link i am updating jobEditTable and hiding that p:dialog.

    <p:datatable id="jobEditTable" value="#{mastersBean.dataList}"..../>
 . . .. . . .  . . .
    <p:commandLink  actionListener="#{tableBean.deleteRow}" update="jobEditTable"  oncomplete="deleteJob.hide()">
               <p:graphicImage value="/images/delete_button.png" />
                 <f:attribute name="model" value="#{tableBean.delCode}"></f:attribute>
                </p:commandLink>

All is working fine datatable is also refreshing.

BUT if we search for some jobs before deleting and doing that process than data table is not refreshing. WHY??

Means, data table is refreshing if i am not using any filter means without search if i delete some row then data table is refreshing but after searching and on deleting data table is not refreshing..

Why it is behaving like this ??

My bean in view scope.

This is my ManagedBean named MastersBean

  public void deleteDetails(ActionEvent e)
    {
        String id=(String)e.getComponent().getAttributes().get("param");
        ........deleting data from database according to id.........
            dataList.clear();

      ..........updating datalist again....................
        FacesContext context = FacesContext.getCurrentInstance();  

        context.addMessage(null, new FacesMessage("Successfully Deleted"));  

    }

Upvotes: 0

Views: 3408

Answers (3)

Boris_Ndong
Boris_Ndong

Reputation: 247

I would suggest using a ListIterator<Object>:

void delete(Object object) {
    ListIterator<Object> iter = myArrayList.listIterator()

    while (iter.hasnext) {
        if (current element == object) {
            ------dataBase call here to delete object----
            iter.remove();
        }
    }
}

Upvotes: 0

Mohammad
Mohammad

Reputation: 21

I think after removing the item from database , you need to remove selected item from your array list too like: myArrayList.remove(selectedItem);, dont reload all data again from database !! . I had this problem and now it s working well .

Upvotes: 2

Akos K
Akos K

Reputation: 7133

Try to update the form around your dataTable in the ajax update:

<h:form id="form1">
....
    <p:datatable id="jobEditTable" ..../>
</h:form>

<p:commandLink ... update=":form1"...></p:commandLink>

Is the result what you are showing on the dataTable cached in the backing bean? Could you post the source of your backing bean?

Upvotes: 0

Related Questions