简体   繁体   English

使用ManagedBean jsf2 primefaces中的代码编辑数据表

[英]edit datatable with code in managedBean jsf2 primefaces

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 : 我有一个数据表,当用户选中或取消选中其chceckbox之一时,我想通过编程来编辑其组件的值:

<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 : 这是managedBean:

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

}

also in the managedBean I have : 在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;
}

like you see above, I use the binding attribute to link the datatable with the managedBean but when I use 就像您在上面看到的那样,我使用binding属性将数据表与managedBean链接起来,但是当我使用

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 我没有在数据表上看到我的更改,您有任何想法吗,谢谢

You're not updating your datatable on the client side to reflect the changes you made on the server side. 您不会在客户端更新数据表以反映您在服务器端所做的更改。 Refresh the datatable via ajax using update= "carList" to the ajax event. 使用update= "carList"通过ajax将数据表update= "carList"到ajax事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM