0

我使用具有复选框选择功能的数据表,但是当我在选择某些行后单击页脚按钮时,这些行不会受到我的对象 selectedCommandes [] 的影响,证明是我在显示我的方法中添加了一行selectedCommandes[] 的长度,但它返回 0,我不知道为什么,我认为我所有的代码都很好,这里是数据表:

<p:dataTable id="cars" var="car" value="#{commandesUserController.mediumCommandesModel}" selection="#{commandesUserController.selectedCommandes}"  tableStyle="width:auto">  


                <f:facet name="header">  
                    Checkbox Based Selection  
                </f:facet>  

                <p:column selectionMode="multiple" style="width:18px" />  

                <p:column headerText="Model" style="width:100px">  
                    <h:outputText value="#{car.id}" />  
                </p:column>  

                <p:column headerText="Year" style="width:100px">  
                    <h:outputText value="#{car.dateEnvoi}" />  
                </p:column>  

                <p:column headerText="Manufacturer" style="width:100px">  
                    <h:outputText value="#{car.dateLivraisonRecommande}" />  
                </p:column>  

                <p:column>
                    <p:commandLink ajax="false" value="Editer" action="updateUser_v1" >
                        <f:setPropertyActionListener value="#{car}" target="#{editUserController.u1}" />  
                    </p:commandLink>
                </p:column>

                <p:column>
                    <p:commandLink  value="Supprimer" oncomplete="confirmation.show()" >
                        <f:setPropertyActionListener value="#{car}" target="#{commandesUserController.selectedCommande}" />  
                    </p:commandLink>
                </p:column>

                <p:column style="width:40px">                         
                    <p:commandButton id="selectButton" update=":myform:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="View">  
                        <f:setPropertyActionListener value="#{car}" target="#{commandesUserController.selectedCommande}" />  
                    </p:commandButton>                       
                </p:column>  


                <f:facet name="footer">  
                    <p:commandButton id="supprion" value="supprimer selection"   oncomplete="confirmation2.show()"   />  
                </f:facet>

            </p:dataTable>  

这是有问题的按钮:

<f:facet name="footer">  
                    <p:commandButton id="supprion" value="supprimer selection"   oncomplete="confirmation2.show()"   />  
                </f:facet>

这是我单击上面的按钮时出现的对话框:

<p:confirmDialog id="confirmDialog2" message="etes vous sur de vouloir supprimer ces commande avec tous les données et fichiers correspondants !"  
                             header="confirmation de suppression" severity="alert" widgetVar="confirmation2">  

                <p:commandButton id="confirm2" value="oui" update="cars" oncomplete="confirmation2.hide()"  
                                 action="#{commandesUserController.deleteCommandes()}" />  
                <p:commandButton id="decline2" value="non" onclick="confirmation2.hide()" type="button" />   

            </p:confirmDialog> 

这是 managedBean 中的方法:

public String deleteCommandes(){
   System.out.println("je suis dans delete l ensemble avec tous    =   "+selectedCommandes.length);
   for(int j = 0;j<selectedCommandes.length;j++){
      selectedCommandes[j].setListFichiers(uh.getFichiersById(this.selectedCommandes[j].getId()));
       for(int i = 0; i<selectedCommandes[j].getListFichiers().size();i++){
       //System.out.println("alors "+selectedCommande.getListFichiers().get(i).getId());
       uh.deleteFichier(selectedCommandes[j].getListFichiers().get(i));
   }
   uh.deleteCommande(selectedCommandes[j]);
   }


    return "commandesUser";

}

这一行: System.out.println("je suis dans delete l ensemble avec tous = "+selectedCommandes.length); 总是返回 0

我已经创建了实现 SelectableDataModel 的类

我希望我能解释问题

你有什么想法吗谢谢

4

3 回答 3

0

添加 <p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" update=":form:messages" />

在下面

<p:datatTable>

于 2014-04-23T15:44:17.070 回答
0

周围有h:form放置p:dataTable吗?如果不是这种情况,这可能是您的问题的原因。

在 PrimeFaces 的展示页面上,结构如下所示:

<h:form>
    <p:dataTable>
        <!-- content of data table -->
    </p:dataTable>

    <p:confirmDialog>
        <!-- content of dialog -->
    </p:confirmDialog>
</h:form>

我猜将p:dataTableand放在p:confirmDialog单独的形式中也应该起作用:

<h:form>
    <p:dataTable>
        <!-- content of data table -->
    </p:dataTable>
</h:form>
<h:form>
    <p:confirmDialog>
        <!-- content of dialog -->
    </p:confirmDialog>
</h:form>

您可以在 setter 上设置断点selectedCommandes以检查是否被调用。(不用担心 setter 被多次调用,这是正常的。)

于 2012-08-22T12:57:34.430 回答
0

正如你告诉我的,我用两种形式在一个单独的页面中进行了测试:这是新的 xhtml 页面:

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./template_utilisateur.xhtml">

            <ui:define name="tohead">             
            </ui:define>
            <ui:define name="content">


                Bienvenue #{userController.u1.nom} #{userController.u1.prenom}
                <br></br><br></br><br></br>
                <h:form id="form">                     

                    <p:dataTable id="cars" var="car" value="#{acceuilUserController.lc_maj}"  tableStyle="width:auto" rowStyleClass="#{(car.lu == false) ? 'red' : null}" >  

                        <p:column headerText="Commande N° : " style="width:100px">  
                            <h:outputText value="#{car.commande.id}" />  
                        </p:column>  

                        <p:column headerText="Date de mise à jour : " style="width:100px">  
                            <h:outputText value="#{car.dateMaj}" />  
                        </p:column> 

                        <p:column headerText="Decision : " style="width:100px">  
                            <h:outputText value="#{car.decison}" />  
                        </p:column> 

                        <p:column headerText="Etat : " style="width:100px">  
                            <h:outputText value="#{car.etat}" />  
                        </p:column> 

                        <p:column style="width:40px">                         
                            <p:commandButton  id="selectButton"  update=":form:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="plus de détails">  
                                <f:setPropertyActionListener value="#{car}" target="#{acceuilUserController.selectedMajCommande}" />  
                            </p:commandButton>                       
                        </p:column> 

                    </p:dataTable>                    

                    <p:dialog header="Commande editée le #{acceuilUserController.selectedMajCommande.dateMaj} par l'#{acceuilUserController.selectedMajCommande.utilisateur.type} #{acceuilUserController.selectedMajCommande.utilisateur.nom} #{acceuilUserController.selectedMajCommande.utilisateur.prenom}" widgetVar="carDialog" resizable="false" id="carDlg"  
                              showEffect="fade" hideEffect="explode" modal="true">  

                        <f:ajax event="close" execute="@this" render="cars" listener="#{acceuilUserController.refreshDatatable()}"/>
                        <table id="gradient-style" >
                            <tr style="border: hidden;">
                                <th>
                                    <h:outputLabel value="Model:" />
                                </th>
                                <td>
                                    <h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.id}" />
                                </td>                                       
                            </tr>
                            <tr style="border: hidden;">
                                <th>
                                    <h:outputLabel value="Year:" />
                                </th>
                                <td>
                                    <h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.etat}" />
                                </td>                                       
                            </tr>
                            <tr style="border: hidden;">
                                <th>
                                    <h:outputLabel value="Manufacturer:" />
                                </th>
                                <td>
                                    <h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.dateEnvoi}" />
                                </td>                                       
                            </tr>
                            <tr style="border: hidden;">
                                <th>

                                    <h:outputLabel value="Color:" />
                                </th>
                                <td>
                                    <h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.dateLivraisonRecommande}" />
                                </td>                                       
                            </tr>
                        </table>
                        <table id="gradient-style" >
                            <th>Nom Fichier</th><th>Taille</th><th>Télécharger</th>
                            <ui:repeat value="#{acceuilUserController.selectedMajCommande.commande.listFichiers}" var="jjjjj">
                                <tr>
                                    <td>
                                        <h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" />
                                    </td>
                                    <td>
                                        <h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" />
                                    </td>
                                    <td>
                                        <h:commandLink value="Télécharger">
                                            <p:fileDownload value="#{jjjjj.convertFichier}" />                                            
                                        </h:commandLink>

                                    </td>
                                </tr>

                            </ui:repeat>

                        </table>

                    </p:dialog>  

                </h:form> 


            </ui:define>

        </ui:composition>

    </body>
</html>

这是 selectedCommandes 的 set 方法:

public void setSelectedCommandes(Commande[] selectedCommandes) {
    System.out.println("je suis la dans son set tous                     :     :"+selectedCommandes.length);
    this.selectedCommandes = selectedCommandes;
}

我注意到,当我检查一行时,上面的方法没有运行,当我点击时它只运行一次:

<f:facet name="footer">  
                <p:commandButton id="supprion" value="supprimer selection" update=":form2:displayMulti"  oncomplete="confirmation2.show()"   />  
            </f:facet>

在数据表的页脚中,它是这样写的:

 Infos: je suis la dans son set tous                     :     :0

你有什么想法吗,谢谢

于 2012-08-23T20:28:38.997 回答