Bonjour à tous.
J'ai un p:datatable éditable avec un total dans le ColumnGroup.
Nom : testTotalisation.jpg
Affichages : 499
Taille : 5,6 Ko

c'est une liste d'items
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@ManagedBean
@ViewScoped
public class Item implements Serializable{
 
    public Item() {}
 
    public String getLibelle() {
        return libelle;
    }
 
    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }
 
    public BigDecimal getMontant() {
        return montant;
    }
 
    public void setMontant(BigDecimal montant) {
        this.montant = montant;
    }
 
    private String libelle;
    private BigDecimal montant;
}
cette liste est pilotée par :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@ManagedBean
@ViewScoped
public class ItemManager implements Serializable {
 
    public ItemManager() {
    }
 
    @PostConstruct
    public void initMethod() {
        items = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            Item item = new Item();
            item.setLibelle("libellé n° " + i);
            item.setMontant(new BigDecimal(0)); // initialisation montant à zéro
            items.add(item);
        }
        totalMontant = "pas calculé";
    }
 
    public List<Item> getItems() {
        return items;
    }
 
    public String getTotalMontant() {
        return totalMontant;
    }
 
    public void setTotalMontant(String totalMontant) {
        this.totalMontant = totalMontant;
    }
 
    public void onCellEdit(CellEditEvent event) {
        BigDecimal total = new BigDecimal(0);
        for (Item item : items) {
            total = total.add(item.getMontant());
        }
        totalMontant = new DecimalFormat("#,##0.00").format(total);
        System.out.println("totalMontant calculé : " + totalMontant);
    }
 
    private List<Item> items;
    private String totalMontant;
}
Chaque fois que je change une valeur dans la colonne Montant, je voudrais que le total s'affiche en bas.

J'ai donc fais un p:remoteCommand pour pouvoir mettre à jour le total :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<p:remoteCommand name="refreshFooter" update=":monform:lignes:totalGroup"/>
chaque fois qu'une cellule est modifiée, refreshFooter est appelé par :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<p:ajax event="cellEdit"  listener="#{itemManager.onCellEdit}" oncomplete="refreshFooter();" />
Au global mon xhtml est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    <h:body>
        <f:view>
            <h:form  id="monform">
 
                <p:remoteCommand name="refreshFooter" update=":monform:lignes:totalGroup"/>
 
                <p:dataTable id="lignes" var="item" value="#{itemManager.items}" editable="true"  editMode="cell"  style="width: 400px">
 
                    <p:ajax event="cellEdit"  listener="#{itemManager.onCellEdit}" oncomplete="refreshFooter();" />
 
                    <p:column headerText="Libellé" style="width: 70%">
                        <p:cellEditor >
                            <f:facet name="output"><h:outputText value="#{item.libelle}" /></f:facet>
                            <f:facet name="input"><p:inputText value="#{item.libelle}" /></f:facet>
                        </p:cellEditor>
                    </p:column>
 
                    <p:column headerText="Montant" style="width: 30%">
                        <p:cellEditor >
                            <f:facet name="output"><h:outputText value="#{item.montant}" /></f:facet>
                            <f:facet name="input"><p:inputText value="#{item.montant}" /></f:facet>
                        </p:cellEditor>
                    </p:column>
 
                    <p:columnGroup type="footer" id="totalGroup" >
                        <p:row >
                            <p:column footerText="totalisation"/>
                            <p:column footerText="#{itemManager.totalMontant}" />
                        </p:row>
                    </p:columnGroup>
 
                </p:dataTable>
            </h:form>
        </f:view>
    </h:body>

Mon problème :
la méthode de totalisation est bien exécutée dans ItemManager
(avec System.out.println("totalMontant calculé : " + totalMontant); j'obtiens bien Infos: totalMontant calculé : 123,00 dans le log)
mais l'affichage ne se fait pas (en dépit du update=":monform:lignes:totalGroup")

Le log me dit aussi :
Avertissement: Can not update component "org.primefaces.component.columngroup.ColumnGroup" with id "monform:lignes:totalGroup" without a attached renderer. Expression ":monform:lignes:totalGroup" referenced from "monform:j_idt5"
Du coup, quelqu'un saurait-il comment attacher un renderer à un ColumnGroup
ou bien aurait une autre solution de contournement (genre un autre composant qui ferait le travail) ?