IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

Collection refresh directement


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut Collection refresh directement
    bonjour,
    j'ai un souci avec les collection qui ne se mette pas a jour directement comment pui-je m'y prendre merci

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Citation Envoyé par mimi6060 Voir le message
    bonjour,
    j'ai un souci avec les collection qui ne se mette pas a jour directement comment pui-je m'y prendre merci
    Bonjour, peux tu repreciser ta question? et merci de bien nous situer dans ton contexte, en rappelant les technologies utilisées, difficile de répondre à de questions aussi vagues

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut
    j'utilise l'entity suivante

    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
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package entity;
     
    import java.io.Serializable;
    import java.math.BigDecimal;
    import java.util.Collection;
    import javax.persistence.Basic;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.Lob;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author Coshom
     */
    @Entity
    @Table(name = "article")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Article.findByCategorie", query = "SELECT a FROM Article a WHERE a.idCateg = :categorie ORDER BY a.nom ASC"),
        @NamedQuery(name = "Article.findByCategorieActiv", query = "SELECT a FROM Article a WHERE a.idCateg = :categorie and a.disponibilite='a' ORDER BY a.nom ASC"),
        @NamedQuery(name = "Article.externe", query = "SELECT a FROM Article a WHERE a.nom = 'Article externe au magasin'"),
        @NamedQuery(name = "Article.findAll", query = "SELECT a FROM Article a "),
        @NamedQuery(name = "Article.findAllByname", query = "SELECT a FROM Article a ORDER BY a.nom ASC"),
        @NamedQuery(name = "Article.findAllBynameActiv", query = "SELECT a FROM Article a WHERE a.disponibilite = 'a' ORDER BY a.nom ASC"),
        @NamedQuery(name = "Article.findAllBynameActivAndStock", query = "SELECT a FROM Article a WHERE a.disponibilite = 'a' AND a.quantite > 0 ORDER BY a.nom ASC"),
        @NamedQuery(name = "Article.findByNumCodeBarre", query = "SELECT a FROM Article a WHERE a.numCodeBarre = :numCodeBarre"),
        @NamedQuery(name = "Article.findByNom", query = "SELECT a FROM Article a WHERE a.nom = :nom"),
        @NamedQuery(name = "Article.findByPrix", query = "SELECT a FROM Article a WHERE a.prix = :prix"),
        @NamedQuery(name = "Article.findByMarque", query = "SELECT a FROM Article a WHERE a.marque = :marque"),
        @NamedQuery(name = "Article.findByQuantite", query = "SELECT a FROM Article a WHERE a.quantite = :quantite"),
        @NamedQuery(name = "Article.findByQuantiteMax", query = "SELECT a FROM Article a WHERE a.quantiteMax = :quantiteMax"),
        @NamedQuery(name = "Article.findByQuantiteMin", query = "SELECT a FROM Article a WHERE a.quantiteMin = :quantiteMin"),
        @NamedQuery(name = "Article.findByGarantie", query = "SELECT a FROM Article a WHERE a.garantie = :garantie"),
        @NamedQuery(name = "Article.findByDisponibilite", query = "SELECT a FROM Article a WHERE a.disponibilite = :disponibilite"),
        @NamedQuery(name = "Article.findByUrl", query = "SELECT a FROM Article a WHERE a.url = :url")})
    public class Article implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @Basic(optional = false)
        @NotNull
        @Column(name = "num_code_barre")
        private Integer numCodeBarre;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 60)
        @Column(name = "nom")
        private String nom;
        @Basic(optional = false)
        @NotNull
        @Lob
        @Size(min = 1, max = 16777215)
        @Column(name = "description")
        private String description;
        @Basic(optional = false)
        @NotNull
        @Lob
        @Size(min = 1, max = 16777215)
        @Column(name = "detail")
        private String detail;
        // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
        @Basic(optional = false)
        @NotNull
        @Column(name = "prix")
        private BigDecimal prix;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 30)
        @Column(name = "marque")
        private String marque;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite")
        private int quantite;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite_max")
        private int quantiteMax;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite_min")
        private int quantiteMin;
        @Basic(optional = false)
        @NotNull
        @Column(name = "garantie")
        private int garantie;
        @Basic(optional = false)
        @NotNull
        @Column(name = "disponibilite")
        private char disponibilite;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 255)
        @Column(name = "url")
        private String url;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Vente> venteCollection;
        @OneToMany(mappedBy = "numCodeBarre")
        private Collection<Reparation> reparationCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Support> supportCollection;
        @JoinColumn(name = "id_categ", referencedColumnName = "id_categ")
        @ManyToOne(optional = false)
        private Categorie idCateg;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Cote> coteCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Commentaire> commentaireCollection;
     
        public Article() {
        }
     
        public Article(Integer numCodeBarre) {
            this.numCodeBarre = numCodeBarre;
        }
     
        public Article(Integer numCodeBarre, String nom, String description, String detail, BigDecimal prix, String marque, int quantite, int quantiteMax, int quantiteMin, int garantie, char disponibilite, String url) {
            this.numCodeBarre = numCodeBarre;
            this.nom = nom;
            this.description = description;
            this.detail = detail;
            this.prix = prix;
            this.marque = marque;
            this.quantite = quantite;
            this.quantiteMax = quantiteMax;
            this.quantiteMin = quantiteMin;
            this.garantie = garantie;
            this.disponibilite = disponibilite;
            this.url = url;
        }
     
        public Integer getNumCodeBarre() {
            return numCodeBarre;
        }
     
        public void setNumCodeBarre(Integer numCodeBarre) {
            this.numCodeBarre = numCodeBarre;
        }
     
        public String getNom() {
            return nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public String getDetail() {
            return detail;
        }
     
        public void setDetail(String detail) {
            this.detail = detail;
        }
     
        public BigDecimal getPrix() {
            return prix;
        }
     
        public void setPrix(BigDecimal prix) {
            this.prix = prix;
        }
     
        public String getMarque() {
            return marque;
        }
     
        public void setMarque(String marque) {
            this.marque = marque;
        }
     
        public int getQuantite() {
            return quantite;
        }
     
        public void setQuantite(int quantite) {
            this.quantite = quantite;
        }
     
        public int getQuantiteMax() {
            return quantiteMax;
        }
     
        public void setQuantiteMax(int quantiteMax) {
            this.quantiteMax = quantiteMax;
        }
     
        public int getQuantiteMin() {
            return quantiteMin;
        }
     
        public void setQuantiteMin(int quantiteMin) {
            this.quantiteMin = quantiteMin;
        }
     
        public int getGarantie() {
            return garantie;
        }
     
        public void setGarantie(int garantie) {
            this.garantie = garantie;
        }
     
        public char getDisponibilite() {
            return disponibilite;
        }
     
        public void setDisponibilite(char disponibilite) {
            this.disponibilite = disponibilite;
        }
     
        public String getUrl() {
            return url;
        }
     
        public void setUrl(String url) {
            this.url = url;
        }
     
        @XmlTransient
        public Collection<Vente> getVenteCollection() {
            return venteCollection;
        }
     
        public void setVenteCollection(Collection<Vente> venteCollection) {
            this.venteCollection = venteCollection;
        }
     
        @XmlTransient
        public Collection<Reparation> getReparationCollection() {
            return reparationCollection;
        }
     
        public void setReparationCollection(Collection<Reparation> reparationCollection) {
            this.reparationCollection = reparationCollection;
        }
     
        @XmlTransient
        public Collection<Support> getSupportCollection() {
            return supportCollection;
        }
     
        public void setSupportCollection(Collection<Support> supportCollection) {
            this.supportCollection = supportCollection;
        }
     
        public Categorie getIdCateg() {
            return idCateg;
        }
     
        public void setIdCateg(Categorie idCateg) {
            this.idCateg = idCateg;
        }
     
        @XmlTransient
        public Collection<Cote> getCoteCollection() {
            return coteCollection;
        }
     
        public void setCoteCollection(Collection<Cote> coteCollection) {
            this.coteCollection = coteCollection;
        }
     
        @XmlTransient
        public Collection<Commentaire> getCommentaireCollection() {
            return commentaireCollection;
        }
     
        public void setCommentaireCollection(Collection<Commentaire> commentaireCollection) {
            this.commentaireCollection = commentaireCollection;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (numCodeBarre != null ? numCodeBarre.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Article)) {
                return false;
            }
            Article other = (Article) object;
            if ((this.numCodeBarre == null && other.numCodeBarre != null) || (this.numCodeBarre != null && !this.numCodeBarre.equals(other.numCodeBarre))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.Article[ numCodeBarre=" + numCodeBarre + " ]";
        }
     
    }
    avec la facade suivante :

    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package session;
     
    import entity.Article;
    import entity.Categorie;
    import entity.Membre;
    import java.util.List;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
     
    /**
     *
     * @author Coshom
     */
    @Stateless
    public class ArticleFacade extends AbstractFacade<Article> {
        @PersistenceContext(unitName = "Coshom-ejbPU")
        private EntityManager em;
     
        @Override
        protected EntityManager getEntityManager() {
            return em;
        }
     
        public ArticleFacade() {
            super(Article.class);
        }
         public List<Article> AllArticleByCategorie (Categorie categorie) {
     
             Query query = em.createNamedQuery("Article.findByCategorie");
                   query.setParameter("categorie",categorie);
                return  query.getResultList();
         } 
           public List<Article> AllArticleByCategorieActiv (Categorie categorie) {
     
             Query query = em.createNamedQuery("Article.findByCategorieActiv");
                   query.setParameter("categorie",categorie);
                return  query.getResultList();
         } 
     
     
     
     
         public List<Article> ArticleAll () {
     
             Query query = em.createNamedQuery("Article.findAllByname");
                return  query.getResultList();
         } 
     
         public List<Article> ArticleAllActiv () {
     
             Query query = em.createNamedQuery("Article.findAllBynameActiv");
                return  query.getResultList();
         } 
         public Article ArticleExterne () {
     
             Query query = em.createNamedQuery("Article.externe");
     
           return  (Article) query.getSingleResult();
        }
            public List<Article> ArticleAllActivAndStock () {
     
             Query query = em.createNamedQuery("Article.findAllBynameActivAndStock");
                return  query.getResultList();
         }
     
     
     
     
    }
    je recupere donc les données de la facon suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     List ListArticle =  articleFacade.ArticleAllActiv (); 
      request.setAttribute("ListArticle",ListArticle);
    jusque la tout se passe bien pour les données

    sauf quand je fais dans ma serlvette :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ${ListArticle.coteCollection}
    dans un foreach bien sur au debut il m'affiche bien la bonne liste de cote mais quand j'en ajouter d'autre je dois attendre un peu avant que les cotes s'affiche enfin comment resoudre ce probleme ?

  4. #4
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Comment rafraichis tu ta collection après ajout?

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut
    j'utilise les fonction suivante pour l'ajout je ne vois pas comment je peux actualiser mes collection :

    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package session;
     
    import java.util.List;
    import javax.persistence.EntityManager;
     
    /**
     *
     * @author Coshom
     */
    public abstract class AbstractFacade<T> {
        private Class<T> entityClass;
     
        public AbstractFacade(Class<T> entityClass) {
            this.entityClass = entityClass;
        }
     
        protected abstract EntityManager getEntityManager();
     
        public void create(T entity) {
            getEntityManager().persist(entity);
     
        }
     
        public void update(T entity) {
            getEntityManager().merge(entity);
     
        }
     
        public void remove(T entity) {
            getEntityManager().remove(getEntityManager().merge(entity));
        }
     
        public T find(Object id) {
            return getEntityManager().find(entityClass, id);
        }
     
        public List<T> findAll() {
            javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
            cq.select(cq.from(entityClass));
            return getEntityManager().createQuery(cq).getResultList();
        }
     
        public List<T> findRange(int[] range) {
            javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
            cq.select(cq.from(entityClass));
            javax.persistence.Query q = getEntityManager().createQuery(cq);
            q.setMaxResults(range[1] - range[0]);
            q.setFirstResult(range[0]);
            return q.getResultList();
        }
     
        public int count() {
            javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
            javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
            cq.select(getEntityManager().getCriteriaBuilder().count(rt));
            javax.persistence.Query q = getEntityManager().createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        }
     
    }

  6. #6
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Difficile de t'aider si tu ne donnes les informations qu'en compte goutte ainsi . Dans quelle page ajoute tu, est ce la même page dans laquelle t'affiche la collection? quel est le rapport entre la page où t'ajoutes et la page ou tu visualises cette collection d'ajout? si l'ajout et la collection se font dans la même page alors il faudrait utiliser une instruction ajax. Peux nous refaire un scénario complet de ton process? où ajoutes tu ? (page d'ajout), et que doit il se passer après l'ajout, en d'autres termes quelle page appelles tu, est ce cette page d'affichage de la liste des côtes? On ne demande qu'à t'aider si tu fais le minimum de bien clarifier ton souci.

Discussions similaires

  1. Refresh WPF Observable Collection
    Par MathieuMN dans le forum Windows Presentation Foundation
    Réponses: 1
    Dernier message: 28/10/2011, 18h45
  2. Accès direct dans Collection
    Par ttttnht dans le forum Collection et Stream
    Réponses: 5
    Dernier message: 15/10/2008, 11h57
  3. Direct Graphics
    Par Blustuff dans le forum DirectX
    Réponses: 9
    Dernier message: 28/10/2002, 04h19
  4. Hors série PCTEAM sur Direct 3D
    Par Shakram dans le forum DirectX
    Réponses: 1
    Dernier message: 12/10/2002, 16h34
  5. La communauté Direct X est au repos?
    Par Shakram dans le forum DirectX
    Réponses: 21
    Dernier message: 18/07/2002, 23h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo