goodprg
goodprg

Reputation: 65

Refresh Datatable after row deletion

I am using PF 3.0RC1 with JSF 2.0.

I have a datatable and on each row I have a delete button. As soon as I press the delete the corresponding row gets deleted from db but the datatable does not get refreshed. It still shows the old set of rows. How can I get the datatable to be refreshed?

Here is the code

   <h:form id="form">
     <p:dataTable  value="#{myController.displayList}" var="item" id="tbl">
       <p:column>
         <p:commandButton image="icon icon-delete"
                          id="del" action="#{myController.del}"
                          update="@form">    
           <f:setPropertyActionListener value="#{item}" 
              target="#{myController.selected}" for="del"/>
         </p:commandButton>
       </p:column>
     </p:dataTable>
   </h:form>

The displayList is

private List<Image> displayList = new ArrayList<Image>();

public List<Image> getDisplayList() {
        Student std = (Student) getSelected;
        displayList = this.ejbFacade.getImages(std.getId()); // this method gets the list of images which has status = 1
        return displayList;
}

public void setDisplayList(List<Image> displayList) {
    this.displayList = displayList;
}

//this is the del method which sets the flag for image to 0 (when del icon is pressed from view) public void del() { selected.setActiveStatus(0); MyController myController = (MyController) facesContext.getApplication().getELResolver(). getValue(facesContext.getELContext(), null, "myController");
displayList.clear(); myController.getFacade().edit(selected); }

Upvotes: 1

Views: 6541

Answers (2)

Daniel
Daniel

Reputation: 37051

if the displayList is the list that holds the values from the table

then

in the delete method you need to do

"set the id of the deleted row into the index variable"

and then do:

displayList.remove(index);

and then delete the row from db

Also try adding process="@this" to the commandButton

Upvotes: 0

spauny
spauny

Reputation: 5096

I'm pretty sure you are deleting the row from the DB but the dataTable records list isn't updated/refreshed. Update you records list by removing the deleted record from the list or by refill the list with the data from the DB(though this would be a bit resource consuming). Show me java code!

PS:Also congratulations you asked the thousandth primefaces question! :) So I'm at your disposal...

Upvotes: 2

Related Questions