简体   繁体   English

具有选择属性的Primefaces数据表-动态表

[英]Primefaces datatable with selection attribute - dynamic tables

First some explain: 首先来解释一下:

I create dynamically an accordeonpanel and in each Tab i create ap:datatable ( also dynamically). 我动态创建一个手风琴面板,并在每个选项卡中创建ap:datatable(也可以动态创建)。

I now have to edit the lines of the tables but my method in the "selection" is not called. 现在,我必须编辑表的行,但是未调用“选择”中的方法。 I think it's because of the above explained dynamism. 我认为是因为上面解释了动态性。

the method is: evaluationController.deleteIndicator() 该方法是:EvaluationController.deleteIndicator()

Does anyone have an idea how to fix that? 有谁知道如何解决这个问题?

Here the code: 这里的代码:

XHTML: XHTML:

<!-- **************************************** ACCORDEON **************************************** -->
            <p:panel id="mainAccordeonHeader" header="Capacités et dégrés de maîtrise" styleClass="panelSearch">
                <h:form id="evalAccordionForm" styleClass="orgForm">      

                    <p:accordionPanel id="evalAccordion" 
                                      styleClass="orgAccordion" 
                                      value="#{evaluationController.availableCapacitys}"
                                      var="capListItem">
                        <p:tab id="evalAccordTitle">
                            <f:facet name="title">
                                <h:panelGrid columns="4">
                                    <h:outputText value="#{capListItem.name}"/>                                      
                                    <h:outputText value="#{capListItem.isThresholdOfSuccess ? 'Capacité Déterminante' : 'Degré de Maitrise'}" />
                                    <h:outputText value="Nr Indicateurs: #{evaluationController.findNumberOfIndicators(capListItem)}"/>
                                    <h:outputText value="Pondération: #{evaluationController.findCapacityPonderation(capListItem)}"/>
                                </h:panelGrid>
                            </f:facet>
                            <!-- CAPACITY DETAIL-->
                            <table border="0" >
                                <thead>
                                    <tr>
                                        <th>
                                            <p>Description</p>
                                        </th>
                                        <th>
                                            <p style="float: right">Pondération</p>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>                                     
                                    <tr>
                                        <td>
                                            <p:inputTextarea id="capDescTextArea" rows="3" cols="113" value="#{capListItem.description}" readonly="true"/>
                                        </td>
                                        <td>
                                            <p:inputTextarea style="float: right" id="capPonderationTextArea"  rows="1" cols="1" readonly="true" value="#{evaluationController.findCapacityPonderation(capListItem)}"/>                                           
                                        </td>
                                    </tr>
                                </tbody>
                            </table>                                    
                            <p:separator />
                            <!-- INDICATORS-->
                            <h:form>
                                <p:contextMenu for="indicatorTable">                               
                                    <p:menuitem value="Modifier" update="indicatorTable" icon="ui-icon-wrench" actionListener="#{evaluationcontroller.updateIndicator()}"/>
                                    <p:menuitem value="Supprimer" update="indicatorTable" icon="ui-icon-trash" actionListener="#{evaluationController.deleteIndicator()}"/>
                                    <p:menuitem value="Ajouter" update="indicatorTable" icon="ui-icon-plus" actionListener="#{evaluationController.addIndicator()}"/>
                                    <p:separator/>
                                     <p:menuitem value="Annuler action"/>
                                </p:contextMenu>
                                <p:dataTable
                                    id="indicatorTable"
                                    value="#{evaluationController.findIndicatorsByCapacity(capListItem)}"                                      
                                    var="indicator"
                                    editable="true"
                                    tableStyle="indicatorTableStyle"     
                                    rowKey="#{indicator.id}"
                                    selection="#{evaluationcontroller.selectedIndicatorRow}" selectionMode="single"
                                    >
                                    <f:facet name="header">Les Indicateurs ( #{evaluationController.findNumberOfIndicators(capListItem)})
                                    </f:facet>
                                    <p:column headerText="Org Ut" >
                                        <h:outputText value ="#{indicator.organizedUt.id}"/>
                                    </p:column>
                                    <p:column headerText="Date">
                                        <h:outputText value ="#{indicator.organizedUt.toString()}"/>
                                    </p:column>
                                    <p:column headerText="Nom">
                                        <h:outputText value ="#{indicator.name}"/>
                                    </p:column>
                                    <p:column headerText="Description" toggleable="false" width="450">
                                        <p:outputLabel value ="#{indicator.description}"  />
                                    </p:column>
                                    <p:column headerText="Max" toggleable="false" width="30">
                                        <p:inputTextarea style="float: none"   rows="1" cols="1" readonly="true" value="#{indicator.maxPossible}"/> 
                                    </p:column>
                                </p:dataTable>    
                                <p:commandButton styleClass="addButtonStyle" icon="ui-icon-plus" value="Ajouter un indicateur"/> 
                                <p:commandButton styleClass="deleteAllButtonStyle" icon="ui-icon-trash" value="Supprimer tous les indicateurs" actionListener="#{evaluationController.deleteIndicator()}"/> 

                            </h:form>
                        </p:tab>
                    </p:accordionPanel>   
                </h:form>
            </p:panel>

CONTROLER: 控制器:

Here is the problem : the Getter Setter are not called when i select a row! 这是问题所在:我选择一行时不调用Getter Setter!

public Indicator getSelectedIndicatorRow() {
    System.out.println("GETTER - selectedIndicatorRow");
    return selectedIndicatorRow;
}

public void setSelectedIndicatorRow(Indicator selectedIndicatorRow) {
    this.selectedIndicatorRow = selectedIndicatorRow;
    System.out.println("SETTER - selectedIndicatorRow");
}


public void deleteIndicator(){
    System.out.println("Function: deleteIndicator");
    try {
        System.out.println("TRY TO DELETE  INDICATOR");
        indicatorFacade.remove(selectedIndicatorRow);

        List<Indicator> tempIndicatorsList = actualGridHM.get(selectedIndicatorRow.getCapacity());
        actualGridHM.remove(selectedIndicatorRow.getCapacity());
        tempIndicatorsList.remove(selectedIndicatorRow);
        actualGridHM.put(selectedIndicatorRow.getCapacity(), tempIndicatorsList);
        System.out.println("INDICATOR DELETED!");
    }
    catch (Exception e) {
        System.out.println("ERROR - DELETE OF INDICATOR NOT WORKED!");
    }

Does anyone have a solution? 有没有人有办法解决吗? Maybe an another way to edit this dynamic table ( placed in a dynamic accordeon)?? 也许是编辑此动态表的另一种方法(放置在动态手风琴中)?

First obvious problem with your code is that you have two <h:form> . 您的代码的第一个明显问题是您有两个<h:form> You have to delete the inner <h:form> and test again. 您必须删除内部的<h:form>并再次进行测试。

Try this way below; 请在下面尝试这种方式; put your command buttons in facets at the bottom of your datatable like 将命令按钮放在数据表底部的构面中,例如

<p:dataTable>
  ...
  <f:facet>
    <p:commandButton styleClass="addButtonStyle" icon="ui-icon-plus" value="Ajouter un indicateur"/> 
    <p:commandButton styleClass="deleteAllButtonStyle" icon="ui-icon-trash" value="Supprimer tous les indicateurs" action="#{evaluationController.deleteIndicator}"/> 
  </f:facet>
</p:dataTable>

and use "action" attribute instead of "actionListener" without '()' at the end of your action method in your command button or add ActionEvent parameter to your action method. 并在命令按钮的操作方法末尾使用不带'()'的“ action”属性而不是“ actionListener”,或将ActionEvent参数添加到您的操作方法中。

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

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