0 Replies Latest reply: Sep 2, 2012 5:45 AM by 959491 RSS

    edit datatable with code in managedBean jsf2 primefaces

    959491
      I have a datatable which I want to edit the value of their component by programing when the user check or uncheck one of their chceckbox here is the datatable :

      <p:dataTable var="car" style="width: 270px;margin-top: 15px;margin-left: 60px" binding="#{editCommandController.hd}" value="#{editCommandController.lp}" id="carList" editable="true">

      <f:facet name="header">
      Stock Papiers
      </f:facet>

      <p:column headerText="Libéllé" style="width:70px">
      <h:outputText value="#{car.libelle}" style="width: 70px;" label="Year"/>
      </p:column>

      <p:column headerText="Stock" style="width:40px">
      <h:outputText value="#{car.stock}" label="Year"/>
      </p:column>

      <p:column headerText="Choisir" style="width:40px;margin: auto;">
      <p:selectBooleanCheckbox id="karim" binding="#{editCommandController.tmp}" value="#{car.checked}" disabled="#{editCommandController.result gt car.stock}" >
      <p:ajax listener="#{editCommandController.checkListener}"/>
      </p:selectBooleanCheckbox>

      </p:column>

      </p:dataTable>

      and here is the managedBean :

      private org.primefaces.component.datatable.DataTable hd;

      public org.primefaces.component.datatable.DataTable getHd() {
      return hd;
      }

      public void setHd(org.primefaces.component.datatable.DataTable hd) {
      this.hd = hd;
      }
      public void checkListener(AjaxBehaviorEvent e) {
      System.out.println("je suis "+e.getComponent().getClientId()+" utilisé : et tmp :" );

      List<Papier> lp1;
      lp1 = new ArrayList();
      lp1 = (List<Papier>) getHd().getValue();
      // getHd().se
      System.out.println("lp1.size() : "+lp1.size());
      Boolean a = true;
      System.out.println("ce bool a = "+a);
      for(int i = 0 ; i< lp1.size();i++){
      System.out.println("alors le cheched est : "+lp1.get(i).getChecked());
      if(lp1.get(i).getChecked()){
      if(lastChecked != null){                  
      for(int j = 0;j<lp1.size();j++){
      if(lp1.get(j).getId().equals(lastChecked)){
      lp1.get(j).setChecked(false);
      break;
      }
      }
      lastChecked = lp1.get(i).getId();
      }else{
      lastChecked = lp1.get(i).getId();
      }

      }

      }
      System.out.println("avant d'affecter voila ce quilya : ");
      for(int i = 0 ; i< lp1.size();i++){
      System.out.println("alors le cheched n "+i+" est : "+lp1.get(i).getChecked());
      }

      org.primefaces.component.datatable.DataTable editdt = new DataTable();
      editdt.setValue(lp1);
      setHd(editdt);
      //getHd().setValue(lp1);

      }


      like you see above, I use the binding attribute to link the datatable with the managedBean but when I use


      org.primefaces.component.datatable.DataTable editdt = new DataTable();
      editdt.setValue(lp1);
      setHd(editdt);
      //getHd().setValue(lp1);


      I don't see my changes on the datatable do you have any idea
      thanks