Bonjour,

Le dataTable de mon application s'actualise uniquement quand je me déconnecte à l'application et je me connecte de nouveau pour prendre en charge la donnée qui vient d'être saisie.

Voici ce qui se passe:


Nom : ecran1.png
Affichages : 526
Taille : 30,2 Ko

On clic sur catégorie pour ajouter une nouvelle catégorie

Nom : ecran2.png
Affichages : 448
Taille : 23,0 Ko

J'enregistre

Nom : ecran3.png
Affichages : 479
Taille : 36,4 Ko

Je vérifie dans la bdd pour voir si la donnée est bien enregistré

Nom : ecran4.png
Affichages : 443
Taille : 15,0 Ko

Revenons dans l'application, cliquons sur le lien catégorie pour appeler la page categorie.xhtml

Nom : ecran5.png
Affichages : 486
Taille : 30,1 Ko

La donnée ne s'affiche pas.

Mais après déconnexion et reconnexion, elle s'affiche:

Nom : ecran6.png
Affichages : 460
Taille : 29,7 Ko

Le beans managé se présente comme suit:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation;
 
import entites.Categorie;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
import services.CategorieImpService;
import services.ICategorieService;
 
/**
 *
 * @author ERIWANG
 */
@ManagedBean(name="categorieBean")
@SessionScoped
public class CategorieBean {
    private String codecat;
    private String designcat;
 
    //délcaration des objets du type liste des categories
    private List<Categorie>categorieList;
    //liaison couche service et presentation
    private ICategorieService services=new CategorieImpService();
 
    public CategorieBean() {
    }
 
    @PostConstruct
    public void initBean(){
        System.out.println("PostConstruct");
        //chargement de la liste
        categorieList=services.listCategorie();    
        System.out.println("liste categorie rechargee ");
    }
 
    public String getCodecat() {
        return codecat;
    }
 
    public void setCodecat(String codecat) {
        this.codecat = codecat;
    }
 
    public String getDesigncat() {
        return designcat;
    }
 
    public void setDesigncat(String designcat) {
        this.designcat = designcat;
    }
 
    public List<Categorie> getCategorieList() {
        return categorieList;
    }
 
    public void setCategorieList(List<Categorie> categorieList) {
        this.categorieList = categorieList;
    }
 
    public ICategorieService getServices() {
        return services;
    }
 
    public void setServices(ICategorieService services) {
        this.services = services;
    }
 
    public String enregistrer() {
       System.out.println("nous sommes dans enregistrer");
       System.out.println("code cat:"+codecat+" - design:"+designcat);
        if(codecat.equals("") || designcat.equals("")){
            System.out.println("nous sommes dans if");
            FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage("Aucun champ vide n'est autorisé!"));
            RequestContext.getCurrentInstance().update("administration:msg");
 
        }else{
            System.out.println("nous sommes dans else");
            //creation un objet categorie
            Categorie ca=new Categorie();
            ca.setCodecat(codecat);
            ca.setDesigncat(designcat);
 
            String reussie=services.creerCategorie(ca);
 
            System.out.println("reponse:"+reussie);
            if(reussie.equalsIgnoreCase("reussie")){
                //message de confirmation(Ce message peut aussi être affiché par FacesContext)
 
                FacesContext.getCurrentInstance().addMessage(null,
                     new FacesMessage("Opération réussie avec succès."));
            }
 
            if(reussie.equalsIgnoreCase("doublons")){
                FacesContext.getCurrentInstance().addMessage(null,
                     new FacesMessage("Duplication des données")); 
            }           
            codecat="";
            designcat=""; 
        }         
 
       return null;
    }
 
 
}

categorie.xhtml:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
<?xml version='1.0' encoding='UTF-8' ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:p="http://primefaces.org/ui"
		template="/resources/templates/generalTemplate.xhtml">
 
    <ui:define name="title">
        Catégorie
    </ui:define>
 
    <ui:define name="content">       
 
     <div class="panel-body">
        <h:link outcome="insertcategorie" value="Nouvelle categorie" class="btn btn-primary"/>
 
      </div>
 
        <!--AFFICHAGE DES DONNEES DANS UN DATATABLE -->
        <div class="panel panel-primary">
            <div class="panel-heading">					
                LISTE DES CATEGORIES					
            </div>
            <div class="panel-body">
                <!--nous aurons besoin d'un dataTable qui doit être lié 
                à une collection des données qui est un attribut du bean-->
                      <h:form> 
 
                     <!--grille des données-->
                     <p:dataTable id="dtCategorie" value="#{categorieBean.categorieList}"
                             var="cat" widgetVar="categorieTable"
                             class="table table-striped"
                             rows="5"
                             paginator="true" paginatorPosition="bottom"
                            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="5,10,15"
                            >
                         <f:facet name="header">
                            <p:outputPanel>
                                <h:outputText value="Search all fields:" />
                                <p:inputText id="globalFilter" onkeyup="PF('categorieTable').filter()" style="width:150px" placeholder="Entre un mot clé"/>
                            </p:outputPanel>
                        </f:facet>
 
                         <p:column headerText="CodeCat" filterBy="#{cat.codecat}" filterMatchMode="contains">
                              <p:outputLabel value="#{cat.codecat}"/>
                          </p:column>
 
                         <p:column headerText="Designation" filterBy="#{cat.designcat}" filterMatchMode="contains">
                              <p:outputLabel value="#{cat.designcat}"/>
                          </p:column>
 
                         <p:column headerText="Modifier" >
                             <p:commandLink 
                                 action="#{categorieBean.edition()}" 
                                class="btn btn-primary" >
                              <p:graphicImage library ="images" name="edits.png"/>                                   
                              <f:param name="idcat" value="#{cat.codecat}"></f:param>
                              <f:param name="operation" value="edition"></f:param>
                           </p:commandLink>
                        </p:column>
 
                        <p:column headerText="Supprimer" >
                             <p:commandLink                                  
                                  action="#{categorieBean.supprimer}" 
                                  class="btn btn-primary" >
                              <p:graphicImage library ="images" name="deletes.png"/>                                   
                              <f:param name="zcodecat" value="#{cat.codecat}"></f:param>
                           </p:commandLink>
                        </p:column>
 
              </p:dataTable>                
 
             </h:form>               
 
 
            </div><!--fin div panel body-->
        </div> <!--fin div panel panel primary-->        
 
 
    </ui:define>
 
</ui:composition>