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:
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
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 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 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); } }
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>
Partager