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

JSF Java Discussion :

Utilisation d'un managed-bean session dans un autre Bean


Sujet :

JSF Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    128
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 128
    Points : 61
    Points
    61
    Par défaut Utilisation d'un managed-bean session dans un autre Bean
    Salut à tous,

    J'ai repris un projet déjà existant et je n 'arrive pas à re-récupérer une variable dans un de mes bean, le projet utilise déjà cette méthode pour stocker une variable session dans un bean et j'aimerais récupérer une autre variable session (bien existante) dans un autre bean. Cependant j'ai un soucis, la récupération ne fonctionne pas la variable reste à "null".

    Voici le managed bean (l'existant "tourneeController" fonctionne bien, mais DspourDaoBase ne fonctionne pas) :
    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
     
      <managed-bean>
        <managed-bean-name>tourneeController</managed-bean-name>
        <managed-bean-class>lims.jsf.controller.PlanningPrelevementController</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
          <property-name>webservice</property-name>
          <value>#{sessionScope.webservice}</value>
        </managed-property>
      </managed-bean>
     
     
     
       <managed-bean>
        <managed-bean-name>DSpourDaoBase</managed-bean-name>
        <managed-bean-class>lims.jsf.hibernate.daoBase</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
          <property-name>ds</property-name>
          <value>#{sessionScope.utilisateur.datasource}</value>
        </managed-property>
      </managed-bean>
    Ma classe daoBase du managed bean non fonctionnel:

    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
     
    package lims.jsf.hibernate;
     
    public abstract class daoBase {
     
    	private Transaction tr = null;
    	private Session session = null;
    	//penser à récupérer le datasource
    	private String ds = null;
     
     
    	protected daoBase() {
    		System.out.println("PASSAGE daoBase" + ds);
    		session = HibernateSessionFactory.getSession();
    	}
     
    //...
    La classe PlanningPrelevementController du managed bean fonctionnel

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package lims.jsf.controller;
     
    public class PlanningPrelevementController {
     
    	private PlanningPrelevementModel model;
    	private Date date = new Date();
    	private String format = "dd/MM/yy";
    	private String mode = "month";
    	private TourneeBean tourneeDrop = null;
    	private Date dateDrop = null;
    	private ILimsWebJSF webservice = null;
    	private Integer idClientAjout = null;
     
    //...

    Aurais je oublié de configurer quelque chose ?

    Par avance merci

  2. #2
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    et le bean utilisateur est bien déclaré?

    NB: tu n'a pas besoin de spécifier sessionScope..

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    128
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 128
    Points : 61
    Points
    61
    Par défaut
    Le bean utilisateur doit être déclaré quelque part pour être utilisé par un managed bean ?

    Sinon voici le bean en question :

    "AuthentificationBean"
    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
     
    package lims.bean;
     
    import java.io.Serializable;
    import java.util.Vector;
     
     
    public class AuthentificationBean implements Serializable {
     
    	private String utilisateur, password, datasource, path, login, base;
    	private String laboratoire, formule, libelleClient, urlServlet, autresClient;
    	private Integer client, maxForfait, idLims, idLaboratoire, idUtilisateur;
    	private Float forfait, horsForfait;
    	private int service;
    	private Vector<ServiceForfaitBean> services;
    	private boolean administrateur;
    	private String adresseIP;
     
     
    	public String getAdresseIP() {
    		return adresseIP;
    	}
     
     
    	public void setAdresseIP(String adresseIP) {
    		this.adresseIP = adresseIP;
    	}
     
     
    	public int getService() {
    		return service;
    	}
     
     
    	public void setService(int service) {
    		this.service = service;
    	}
     
     
    	public Float getForfait() {
    		return forfait;
    	}
     
     
    	public void setForfait(Float forfait) {
    		this.forfait = forfait;
    	}
     
     
    	public String getFormule() {
    		return formule;
    	}
     
     
    	public void setFormule(String formule) {
    		this.formule = formule;
    	}
     
     
    	public Float getHorsForfait() {
    		return horsForfait;
    	}
     
     
    	public void setHorsForfait(Float horsForfait) {
    		this.horsForfait = horsForfait;
    	}
     
     
    	public String getLaboratoire() {
    		return laboratoire;
    	}
     
     
    	public void setLaboratoire(String laboratoire) {
    		this.laboratoire = laboratoire;
    	}
     
     
    	public String getLogin() {
    		return login;
    	}
     
     
    	public void setLogin(String login) {
    		this.login = login;
    	}
     
     
    	public AuthentificationBean() {
     
    	}
     
     
    	public Integer getClient() {
    		return client;
    	}
     
     
    	public void setClient(Integer client) {
    		this.client = client;
    	}
     
     
    	public String getDatasource() {
    		return datasource;
    	}
     
     
    	public void setDatasource(String datasource) {
    		this.datasource = datasource;
    	}
     
     
    	public String getPath() {
    		return path;
    	}
     
     
    	public void setPath(String path) {
    		this.path = path;
    	}
     
     
    	public String getUtilisateur() {
    		return utilisateur;
    	}
     
     
    	public void setUtilisateur(String utilisateur) {
    		this.utilisateur = utilisateur;
    	}
     
     
    	public String getPassword() {
    		return password;
    	}
     
     
    	public void setPassword(String password) {
    		this.password = password;
    	}
     
     
    	public Integer getMaxForfait() {
    		return maxForfait;
    	}
     
     
    	public void setMaxForfait(Integer maxForfait) {
    		this.maxForfait = maxForfait;
    	}
     
     
    	public Integer getIdLims() {
    		return idLims;
    	}
     
     
    	public void setIdLims(Integer idLims) {
    		this.idLims = idLims;
    	}
     
     
    	public Vector<ServiceForfaitBean> getServices() {
    		return services;
    	}
     
     
    	public void setServices(Vector<ServiceForfaitBean> services) {
    		this.services = services;
    	}
     
     
    	public String getLibelleClient() {
    		return libelleClient;
    	}
     
     
    	public void setLibelleClient(String libelleClient) {
    		this.libelleClient = libelleClient;
    	}
     
     
    	public String getBase() {
    		return base;
    	}
     
     
    	public void setBase(String base) {
    		this.base = base;
    	}
     
     
    	public Integer getIdLaboratoire() {
    		return idLaboratoire;
    	}
     
     
    	public void setIdLaboratoire(Integer idLaboratoire) {
    		this.idLaboratoire = idLaboratoire;
    	}
     
     
    	public String getUrlServlet() {
    		return urlServlet;
    	}
     
     
    	public void setUrlServlet(String urlServlet) {
    		this.urlServlet = urlServlet;
    	}
     
     
    	public Integer getIdUtilisateur() {
    		return idUtilisateur;
    	}
     
     
    	public void setIdUtilisateur(Integer idUtilisateur) {
    		this.idUtilisateur = idUtilisateur;
    	}
     
     
    	public boolean isAdministrateur() {
    		return administrateur;
    	}
     
     
    	public void setAdministrateur(boolean administrateur) {
    		this.administrateur = administrateur;
    	}
     
     
    	public String getAutresClient() {
    		return autresClient;
    	}
     
     
    	public void setAutresClient(String autresClient) {
    		this.autresClient = autresClient;
    	}
    }

    En faite les session http sont créés à partir du login de connexion, via cette page :

    "Connection.jsp"
    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
     
    <%@ page language="java" import="lims.util.*, lims.bean.AuthentificationBean, lims.webservice.ILimsWeb" errorPage="" isELIgnored="false" %>
     
    <%@page import="org.hibernate.cfg.Configuration"%>
    <%@page import="org.hibernate.Hibernate"%>
    <%@page import="lims.jsf.hibernate.HibernateSessionFactory"%><jsp:useBean id="webservice" scope="session" class="lims.webservice.ILimsWebJSF"/>
     
    <% 
    	String redirect = "logout.jsp";
     
    	if (!Outil.IsNull(request.getParameter("utilisateur")) && !Outil.IsNull(request.getParameter("motdepasse"))) {
    		ILimsWeb iportail = new ILimsWeb(); iportail.setAliasSQL("PortailLims");
    		AuthentificationBean bean = iportail.authentificationPortail(request.getParameter("utilisateur"), request.getParameter("motdepasse"));
     
    		if (bean != null) {
    			session.setAttribute("utilisateur", bean);
     
    			webservice.setAliasSQL(bean.getDatasource());
    			webservice.setPath(bean.getPath());
    			webservice.setIdentifiantLims(bean.getIdLims());
    			webservice.setUrlServlet(bean.getUrlServlet());
     
    			redirect = "index.xhtml";	
    		}
    	}
     
    	response.sendRedirect(redirect);
    %>

  4. #4
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    tu mélange jsp et jsf, on ne fait plus ce genre de trucs avec JSF, tu dois utiliser que les values binding et EL expression.
    tu dois avoir un bean utilisateur déclaré dans le faces-config.

Discussions similaires

  1. Réponses: 0
    Dernier message: 15/09/2014, 17h04
  2. Réponses: 4
    Dernier message: 23/01/2008, 16h46
  3. Utiliser une valeur d'un formulaire dans un autre ?
    Par jessy212 dans le forum Access
    Réponses: 3
    Dernier message: 21/08/2006, 13h05
  4. [Avancé] Recopie une session dans un autre client
    Par gregoun dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 29/06/2004, 12h11
  5. pb d'utilisation du resultat d'1 requete dans 1 autre
    Par joquetino dans le forum Langage SQL
    Réponses: 7
    Dernier message: 09/03/2004, 15h58

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