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 :

Application JSF 2.0: problème avec les services


Sujet :

JSF Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut Application JSF 2.0: problème avec les services
    bonjour;
    j'ai le meme prob et je n'arrive pas a le resoudre

    j'ai un loginBean qui utilise un service AbService qui posséde la methode "authentification" mais le resultat est toujours NULL:

    loginBean:
    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
    package com.fst.projet.web;
     
    import java.io.Serializable;
     
    import javax.faces.application.FacesMessage;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;
     
     
    import org.hibernate.SessionFactory;
    import org.primefaces.context.RequestContext;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
     
    import com.fst.projet.model.Abonne;
    import com.fst.projet.service.AbService;
     
     
    @ManagedBean(name="loginBean")
    @SessionScoped
    public class LoginBean implements Serializable {
     
    @ManagedProperty(value="#{abonneService}") 
    private AbService abonneService;
     
    private String user; 
     
    private String pass; 
     
     
    public AbService getAbonneService() {
    return abonneService;
    }
     
    public void setAbonneService(AbService abonneService) {
    this.abonneService = abonneService;
    }
     
     
     
     
     
     
    public SessionFactory getSessionFactory() {
    return sessionFactory;
    }
     
    public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
    }
     
    public String getUser() {
    return user;
    }
     
    public void setUser(String user) {
    this.user = user;
    }
     
    public String getPass() {
    return pass;
    }
     
    public void setPass(String pass) {
    this.pass = pass;
    }
     
     
     
     
     
     
    private Abonne A;
     
    public Abonne getA() {
    return A;
    }
     
    public void setA(Abonne a) {
    A = a;
    }
     
     
     
    public Abonne getK() {
    return k;
    }
     
     
    public void setK(Abonne k) {
    this.k = k;
    }
     
     
    public Abonne k;
     
     
    @Autowired
    private SessionFactory sessionFactory; 
     
     
    public String login() { 
     
    RequestContext context = RequestContext.getCurrentInstance(); 
    FacesMessage msg = null; 
    boolean loggedIn = false; 
     
    //username="admin";
    //password="admin";
    if(user != null && pass!= null) {
     
    loggedIn = true;
     
     
    k= abonneService.authentification(user, pass);
    // k=abonneService.findById(user);
    // k=new Abonne(username,password);
    System.out.print("aaaaaaaaaaaaaaaaaaaaaaaaaa");
     
    if(k!=null){
    msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", k.getNomAbonne());
    System.out.print(k.getNomAbonne());
    return "greeting";
     
    }else { 
    loggedIn = false; 
    System.out.print("no");
    return "profile";
    //msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials"); 
    }
    }
    return null;
     
    // FacesContext.getCurrentInstance().addMessage(null, msg);
    }
     
     
    }
    le AbServiceImp:

    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
    package com.fst.projet.service;
     
    import java.util.List;
     
    import javax.ejb.EJB;
    import javax.jws.WebService;
     
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Controller;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
     
    import com.fst.projet.model.Abonne;
    import com.fst.projet.model.Reclamation;
     
     
    @Service(value="abonneService")
    @Transactional
    public class AbServiceImp implements AbService {
     
    @Autowired
    private SessionFactory sessionFactory;
     
     
     
     
    @Override
    public void ajoutab(Abonne ab) {
    sessionFactory.getCurrentSession().saveOrUpdate(ab);
     
    }
     
    @Override
    public void suppab(Abonne ab) {
    sessionFactory.getCurrentSession().delete(ab);
     
    }
     
    @SuppressWarnings("unchecked")
    @Override
    public List<Abonne> findAll() {
    return sessionFactory.getCurrentSession().createQuery("from Abonne").list();
    }
     
    @Override
    @Transactional
    public Abonne authentification(String username, String password) {
    Abonne A=(Abonne) sessionFactory.getCurrentSession().createQuery("select u from Abonne u where u.username = '" + username + "' and u.password='" + password + "'").uniqueResult();
    if (A!=null){return A;}
    return null;
     
    }
     
    public Abonne findById(String username)
    {
    return (Abonne) sessionFactory.getCurrentSession().get(Abonne.class, username);	
     
     
     
    }
     
     
     
    }
    le faces-config.xml:
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlnsi="http://www.w3.org/2001/XInclude"
    xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
     
     
     
    <application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>
     
     
     
    <managed-bean>
    <managed-bean-name>loginBean</managed-bean-name>
    <managed-bean-class>com.fst.projet.web.LoginBean</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/pages/inputname.xhtml</from-view-id>
    <navigation-case>
    <from-outcome>greeting</from-outcome>
    <to-view-id>/pages/greeting.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>profile</from-outcome>
    <to-view-id>/pages/profile.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>reclamation</from-outcome>
    <to-view-id>/pages/reclamation.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>resiliation</from-outcome>
    <to-view-id>/pages/resiliation.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>facture</from-outcome>
    <to-view-id>/pages/facture.xhtml</to-view-id>
    </navigation-case>
    </navigation-rule>
     
     
     
    <application>
    <resource-bundle>
    <base-name>resources</base-name>
    <var>msgs</var>
    </resource-bundle>
    </application>
    </faces-config>
     
     
    l'app-context: 
     
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schem...ring-beans.xsd" target="_blank">http://www.springframework.org/schem...ring-beans.xsd</a>
    <a href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a> <a href="http://www.springframework.org/schem...ng-aop-2.5.xsd" target="_blank">http://www.springframework.org/schem...ng-aop-2.5.xsd</a>
    <a href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schem...ontext-2.5.xsd" target="_blank">http://www.springframework.org/schem...ontext-2.5.xsd</a>
    <a href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a> http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/university"/>
    <property name="username" value="root"/>
    <property name="password" value=""/>
    </bean>
     
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="annotatedClasses">
    <list>
    <value> com.fst.projet.model.Abonne</value>
    <value> com.fst.projet.model.Abonnement</value>
    <value> com.fst.projet.model.TypeAbonnement</value>
    <value> com.fst.projet.model.TypeReclamation</value>
    <value> com.fst.projet.model.Reclamation</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernateDialect"> org.hibernate.dialect.MySQLInnoDBDialect </prop>
    </props>
    </property>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config/>
    <context:component-scan base-package="com.fst.projet"/>
     
     
     
     
     
    </beans>

  2. #2
    Membre actif Avatar de Jacobian
    Inscrit en
    Février 2008
    Messages
    425
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 425
    Points : 245
    Points
    245
    Par défaut
    ton service abonneService tu l'a pas déclarer dans le fichier de configuration de spring ?

  3. #3
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut
    j'utilise la technique d'annotation donc j'ai pas besoin de declarer le bean dans le fichier face-config

  4. #4
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Bizarre,

    je ne vois rien qui cloche, car c'est bien EL resolver Spring à déclarer dans le faces-config qui permet de faire la liaison "JSF / Spring" ...
    et tu as bien cette déclarartion.

    Rien dans le log de ton serveur d'app ?

  5. #5
    Membre actif Avatar de Jacobian
    Inscrit en
    Février 2008
    Messages
    425
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 425
    Points : 245
    Points
    245
    Par défaut
    vas y montre moi la technique que t'utilise pour déclarer ce service peux etre je connais pas cette technique ?

  6. #6
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Citation Envoyé par Jacobian Voir le message
    vas y montre moi la technique que t'utilise pour déclarer ce service peux etre je connais pas cette technique ?
    C'est grâce à ça, dans son fichier de config Spring :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <context:annotation-config/>
    <context:component-scan base-package="com.fst.projet"/>

  7. #7
    Membre actif Avatar de Jacobian
    Inscrit en
    Février 2008
    Messages
    425
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 425
    Points : 245
    Points
    245
    Par défaut
    ça ne suffit pas

  8. #8
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Citation Envoyé par Jacobian Voir le message
    ça ne suffit pas
    que manque-t-il alors ?

  9. #9
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut
    bonjour a tous;

    j'ai corrigée l'erreur! en faite j'ai déclarée mon managed bean deux fois par annotation et dans le faces-config ce qui a provoqué un conflits (une faute d'inattention )). a propos le code il est tout a fait correct

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème avec les services web rest sur android
    Par JacNar6 dans le forum API standards et tierces
    Réponses: 9
    Dernier message: 24/09/2013, 17h41
  2. Réponses: 6
    Dernier message: 04/08/2010, 15h21
  3. Problèmes avec les Services Intenet windows(IIS)
    Par mikawell3000 dans le forum C#
    Réponses: 1
    Dernier message: 26/07/2007, 11h55
  4. Réponses: 1
    Dernier message: 09/08/2006, 17h05
  5. Problèmes avec les services NT/Windows 2000
    Par newfsch dans le forum API, COM et SDKs
    Réponses: 3
    Dernier message: 02/03/2006, 16h49

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