Rodik
Rodik

Reputation: 271

How to update a component in the context of many entries?

I'm using JSF 2.2 and primefaces 6.0

And I have a table in this form

        <table>
            <tr>
                <td rowspan="2">
                    Direction
                </td>
                    <td colspan="#{etpBean.activites.size()}">
                    Activites
                </td>
                </td>
                    <td rowspan="2">
                    Controle
                </td>
            </tr>

            <tr>
              <ui:repeat var="activite" value="#{etpBean.activites}">
                        <td>
                            <h:outputText value="#{activite.nom}"/>
                        </td>
              </ui:repeat>
            </tr>

            <ui:repeat value="#{etpBean.affectations}" var="affectation">
               <tr> 
                <ui:repeat var="activite" value="#{etpBean.activites}">

                <td rowspan="#{etpBean.affectations.size()}"><h:outputText  value="#{affectation.structure.nom}" />
                </td>

                <td>
                    <p:inputText value="#{etpBean.getValeurActivite(affectation,activite).etp}" required="true">
                    <p:ajax listener="#{etpBean.onControleChange(affectation)}" update="controle" event="blur" />
                    </p:inputText>                                                  
                </td>
                <td>    
                <h:outputText id="controle" value="#{etpBean.message}"/>
                </td>
                </ui:repeat>
               </tr> 
            </ui.repeat>
      </table>

For each row of this table i have many inputs of the same type, in my listener onControleChange i retrieve the values of these inputs As i calculate the sum after each entry and i want to update the column controle if the sum more than 100 i want to put not ok else Ok.

Here is the onControleChange

public void onControleChange(Affectation affectation){
    double somme=0;

    for (ETP  etp : etpss) {

        if(etp.getAffectation().equals(affectation) && etp.getEtp() != null){
            somme+=etp.getEtp();
        }
    affectation.setSomme(somme);
    }
    if(somme>100){
        this.message="Not ok";
    }else{
        this.message="Ok";
    }
}

but when i run my XHTML this error appears

Grave: org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "controle" referenced from "form:j_idt77:0:j_idt94:0:j_idt96".

I don't know if it's because of ui: repeat all of the column " contrôle " takes the same id.

Any idea ??

Upvotes: 1

Views: 585

Answers (1)

CHARAFI Saad
CHARAFI Saad

Reputation: 1440

Did you try

<p:ajax listener="#{etpBean.onControleChange(affectation)}" process="@this" update=":#{p:component('controle')}" event="blur" />

Upvotes: 1

Related Questions