Bonjour,
Je piétine toujours avec mon premier projet Seam.
Je cherche à transmettre le nom et le prénom de la personne à sa page d'accueil après qu'elle se soit authentifiée.
Authenticate.java :
AccueilEtudiant.java :
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 @Name("authenticator") public class Authenticator { @Logger private Log log; @In Identity identity; @In Credentials credentials; @In EntityManager entityManager; private String pageSuivante = "/home.xhtml"; @Out(value="Nom", required=false) private String nom; @Out(value="Prenom", required=false) private String prenom; public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getPrenom() { return this.prenom; } public String getPageSuivante() { return this.pageSuivante; } public void setPageSuivante(String page) { this.pageSuivante = page; } public boolean authenticate() { try { log.info("authenticating {0}", credentials.getUsername()); Query query = entityManager.createQuery( "FROM ThUtilisateurUti u " + "WHERE u.utiLogin = :username " + "AND u.utiMotPasse = :password"); query.setParameter("username", credentials.getUsername()); query.setParameter("password", ThUtilisateurUti.generateMD5(credentials.getPassword())); ThUtilisateurUti user = (ThUtilisateurUti) query.getSingleResult(); int typeUtilisateur = user.getTeTypeUtilisateurTu().getTuId(); identity.addRole(user.getTeTypeUtilisateurTu().getTuLibelle()); switch (typeUtilisateur) { case 1 : // Administrateur setPageSuivante("/home.xhtml"); return true; case 2 : // Gestionnaire case 3 : // Étudiant setNom(user.getPrsNom()); setPrenom(user.getPrsPrenom()); setPageSuivante("/accueilEtudiant.xhtml"); return true; } setPageSuivante("/login.xhtml"); //return true; return false; } catch (NoResultException ex) { //setPageSuivante("/login.xhtml"); return false; } } }
Extrait de la page d'accueil de l'étudiant :
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 @Name("accueilEtudiant") public class AccueilEtudiant { @Logger private Log log; @In StatusMessages statusMessages; @In("Nom") String nom; @In("Prenom") String prenom; public String voirStages() { // implement your business logic here log.info("accueilEtudiant.voirStages() action called with: #{accueilEtudiant.value}"); statusMessages.add("accueilEtudiant #{accueilEtudiant.value}"); return "/voirStages.xhtml"; } public String completerInfosPersos() { // implement your business logic here log.info("accueilEtudiant.completerInfosPersos() action called with: #{accueilEtudiant.value}"); statusMessages.add("accueilEtudiant #{accueilEtudiant.value}"); return "/infosPersos.xhtml"; } // add additional action methods }
Code xhtml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <ui:define name="body"> <h:form id="accueilEtudiantForm"> <rich:panel> <f:facet name="header">Accueil</f:facet> <p>Bonjour <h:outputText value="#{accueilEtudiant.Prenom} #{accueilEtudiant.Nom}"/>.
Et voici ce que je trouve dans la console...
D'abord un premier paquet qui n'empêche pas la connexion, testé avec un autre utilisateur qui redirige le login sur une page sans passage d'infos :
Juste après ce qui précède, ça passe à la page accueilEtudiant et ça plante l'appli :10:45:21,789 DEBUG [Identity] Login successful for: etutest
10:45:21,790 DEBUG [ResourceLoader] resource bundle missing: login
10:45:21,796 DEBUG [Component] trying to inject with hierarchical context search: identity
10:45:21,796 DEBUG [Component] trying to inject with hierarchical context search: credentials
10:45:21,797 DEBUG [Component] trying to inject with hierarchical context search: entityManager
10:45:21,797 DEBUG [Navigator] redirecting to: /accueilEtudiant.xhtml
10:45:21,798 DEBUG [FacesManager] redirecting to: /stamas/accueilEtudiant.seam?cid=2
10:45:21,798 DEBUG [SeamPhaseListener] committing transaction after phase: INVOKE_APPLICATION 5
10:45:21,799 DEBUG [EntityTransaction] committing JPA resource-local transaction
10:45:21,812 WARN [SeamPhaseListener] uncaught exception, passing to exception handler
java.lang.IllegalStateException: Could not commit transaction
...
Caused by: javax.persistence.RollbackException: Error while commiting the transaction
...
Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.domain.stamas.entity.ThEtudiantEtu
...
10:45:21,815 DEBUG [Exceptions] reading exception mappings from /WEB-INF/pages.xml
10:45:21,821 ERROR [SeamPhaseListener] swallowing exception
java.lang.IllegalStateException: Could not commit transaction
...
Caused by: javax.persistence.RollbackException: Error while commiting the transaction
...
Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.domain.stamas.entity.ThEtudiantEtu
...
Je ne sais pas si le premier paquet d'erreurs entraîne le second ou s'il y a un truc essentiel qui manque dans mon code mais j'avoue que je n'ai pas encore compris les subtilités des @Scope, @In et @Out.10:45:21,827 DEBUG [FacesLifecycle] >>> Begin JSF request for /stamas/accueilEtudiant.seam
10:45:21,828 DEBUG [Manager] Restoring conversation with id: 2
10:45:21,829 DEBUG [SeamPhaseListener] beginning transaction prior to phase: RENDER_RESPONSE 6
10:45:21,829 DEBUG [EntityTransaction] beginning JPA resource-local transaction
10:45:21,829 DEBUG [ManagedPersistenceContext] created seam managed persistence context from EntityManagerFactory
10:45:21,925 DEBUG [Component] trying to inject with hierarchical context search: statusMessages
10:45:21,926 DEBUG [Component] trying to inject with hierarchical context search: Nom
10:45:21,927 DEBUG [SeamPhaseListener] committing transaction after phase: RENDER_RESPONSE 6
10:45:21,927 DEBUG [EntityTransaction] committing JPA resource-local transaction
10:45:21,929 DEBUG [Manager] Discarding conversation state: 2
10:45:21,929 DEBUG [FacesLifecycle] After render response, destroying contexts
10:45:21,929 DEBUG [Contexts] destroying business process context
10:45:21,930 DEBUG [Contexts] destroying conversation context
10:45:21,930 DEBUG [Contexts] destroying: org.jboss.seam.persistence.persistenceContexts
10:45:21,930 DEBUG [Contexts] destroying: org.jboss.seam.core.conversation
10:45:21,930 DEBUG [Contexts] destroying: org.jboss.seam.international.statusMessages
10:45:21,930 DEBUG [Contexts] destroying: entityManager
10:45:21,930 DEBUG [ManagedPersistenceContext] destroying seam managed persistence context for persistence unit: java:/entityManager
10:45:21,930 DEBUG [Contexts] flushing server-side conversation context
10:45:21,930 DEBUG [Contexts] flushing session context
10:45:21,931 DEBUG [Contexts] destroying event context
10:45:21,931 DEBUG [Contexts] destroying: com.sun.faces.util.RequestStateManager
10:45:21,931 DEBUG [Contexts] destroying: org.jboss.seam.core.manager
10:45:21,931 DEBUG [Contexts] destroying: facelets.ContentType
10:45:21,931 DEBUG [Contexts] destroying: org.jboss.seam.transaction.synchronizations
10:45:21,931 DEBUG [Contexts] destroying: org.jboss.seam.web.requestContextPath
10:45:21,931 DEBUG [Contexts] destroying: com.exade.vcp.Filter.ResponseWrapper
10:45:21,931 DEBUG [Contexts] destroying: org.jboss.seam.core.conversationPropagation
10:45:21,931 DEBUG [Contexts] destroying: accueilEtudiant
10:45:21,931 DEBUG [Contexts] destroying: facelets.Encoding
10:45:21,931 DEBUG [Contexts] destroying: com.exade.vcp.Filter.done
10:45:21,931 DEBUG [Contexts] destroying: org.jboss.seam.transaction.transaction
10:45:21,932 DEBUG [Contexts] destroying: org.jboss.seam.web.servletContexts
10:45:21,932 DEBUG [Contexts] destroying: org.jboss.seam.core.events
10:45:21,932 DEBUG [Contexts] destroying: org.jboss.seam.web.requestServletPath
10:45:21,932 DEBUG [Contexts] destroying: ajaxContext
10:45:21,932 DEBUG [FacesLifecycle] <<< End JSF request for /stamas/accueilEtudiant.seam
10:45:21,932 DEBUG [ExceptionFilter] handling uncaught exception
javax.servlet.ServletException: @In attribute requires non-null value: accueilEtudiant.Nom
...
Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: accueilEtudiant.Nom
...
10:45:21,933 DEBUG [ExceptionFilter] exception root cause
org.jboss.seam.RequiredException: @In attribute requires non-null value: accueilEtudiant.Nom
...
10:45:21,934 DEBUG [ExceptionFilter] running exception handlers
10:45:21,934 DEBUG [Lifecycle] After request, destroying contexts
10:45:21,934 DEBUG [Lifecycle] <<< End web request
10:45:21,943 DEBUG [FacesLifecycle] >>> Begin exception recovery
10:45:21,945 DEBUG [Manager] No stored conversation
10:45:21,946 DEBUG [FacesLifecycle] After render response, destroying contexts
10:45:21,946 DEBUG [Contexts] destroying conversation context
10:45:21,947 DEBUG [Contexts] destroying: org.jboss.seam.caughtException
10:45:21,947 DEBUG [Contexts] flushing server-side conversation context
10:45:21,947 DEBUG [Contexts] flushing session context
10:45:21,948 DEBUG [Contexts] destroying event context
10:45:21,948 DEBUG [Contexts] destroying: org.jboss.seam.core.conversationPropagation
10:45:21,948 DEBUG [Contexts] destroying: org.jboss.seam.transaction.transaction
10:45:21,948 DEBUG [Contexts] destroying: org.jboss.seam.core.manager
10:45:21,948 DEBUG [Contexts] destroying: org.jboss.seam.core.events
10:45:21,948 DEBUG [FacesLifecycle] <<< End JSF request for /stamas/accueilEtudiant.seam
10:45:21,948 DEBUG [ExceptionFilter] done running exception handlers
10:45:21,948 ERROR [BaseXMLFilter] Exception in the filter chain
javax.servlet.ServletException: @In attribute requires non-null value: accueilEtudiant.Nom
...
Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: accueilEtudiant.Nom
...
Si quelqu'un connaît un tuto en français qui explique ça en détail, je suis preneur car je sens qu'il me manque des bases.
Et bien sûr la solution immédiate à mon problème m'aiderait aussi à comprendre !![]()
Partager