jsf - Unable to delete rows in datatable multiple times -


i have primefaces datatable table conditional delete button delete row if clicked. clicking on first time works. delete row , table refreshed new table. when try delete table again, table refresh no entries. if update table using 1 of buttons created, table show again entry tried delete still there. looking it, see method in action being called when deleted first 1 successfully. however, when try again, method not being invoked. why isn't it?

<html xmlns="http://www.w3.org/1999/xhtml"     xmlns:ui="http://java.sun.com/jsf/facelets"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:c="http://java.sun.com/jsp/jstl/core"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:p="http://primefaces.org/ui">  <h:head> </h:head> <h:body> <h:form> <p:datatable id="cartable" var="car" value="#{dtbasicview.cars}">             <f:facet name="header">                         car table                     </f:facet>              <p:column headertext="id" sortby="#{car.id}">                 <h:outputtext value="#{car.id}" />             </p:column>              <p:column headertext="year" sortby="#{car.year}">                 <h:outputtext value="#{car.year}" />             </p:column>              <p:column headertext="brand" sortby="#{car.brand}">                 <h:outputtext value="#{car.brand}" />             </p:column>              <p:column headertext="color" sortby="#{car.color}">                 <h:outputtext value="#{car.color}" />             </p:column>              <p:column headertext="delete option">                 <p:commandlink action="#{dtbasicview.deletecar(car)}"                     update="@form" rendered="#{car.iswhite}" value="delete" ajax="true">                 </p:commandlink>             </p:column>     </h:form> </h:body> </html> 

and bean

@managedbean(name="dtbasicview") @viewscoped public class basicview implements serializable {      /**      *       */     private static final long serialversionuid = 1l;     private car selectedcar;     private list<car> cars;     private list<car> onehundredcars;     private int numberofcars=0;      @managedproperty("#{carservice}")     private carservice service;      @postconstruct     public void init() {         onehundredcars = service.createcars(100);     }      public void setnumberofcars(string num) {         this.numberofcars = integer.parseint(num);         cars = onehundredcars.sublist(0, numberofcars);     }      public list<car> getcars() {         return cars;     }      public void setservice(carservice service) {         this.service = service;     }      public car getselectedcar() {         return selectedcar;     }      public void setselectedcar(car selectedcar) {         this.selectedcar = selectedcar;     }       public boolean getisempty() {         return cars == null || cars.isempty();     }      public void deletecar(car car) {         cars.remove(car);         int size = cars.size();         setnumberofcars(""+size);     } } 

a little update: still haven't fixed problem. have shifted things around list not resizeable. whenever click on second delete commandlink, whole datatable gets refreshed new random data.

another update: appears if calling @postconstruct again after hitting second delete. doing so, recreating whole new set of arrays of cars.

after spending whole day yesterday trying figure out why happening, have fixed it. have changed commandlink commandbutton , neither of changes worked. worked me instead of letting button ajax submit, instead non-ajax submit. still not know why worked, if can explain helpful.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -