Bonjour,
J'ai fait un formulaire de login mais l'action associée à mon bouton de connexion ne s'enclenche pas.
Qqun saurait-il m'aider ?
Voici le code :
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 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <f:view locale="#{changeLocale.locale}"> <h:head> <title>Connexion</title> <h:outputStylesheet library="css" name="styles.css" /> </h:head> <body> <h:form id="connexionForm"> <p:growl id="growl" life="2000" /> <p:panelGrid columns="1" style="margin-bottom:15px;" layout="grid"> <f:facet name="header"> <h:outputText class="titreLogin" value="Connexion" /> </f:facet> <p:panelGrid columns="2" styleClass="panelSansBordure"> <h:outputText value="Nom d'utilisateur :" /> </p:panelGrid> <p:inputText id="login" value="#{connexionForm.login}" size="25" /> <p:panelGrid columns="2" styleClass="panelSansBordure"> <h:outputText value="Mot de passe :" /> </p:panelGrid> <p:password id="password" value="#{connexionForm.password}" size="25" /> <p:panelGrid columns="2" style="margin-bottom:15px" styleClass="panelSansBordure"> <p:selectBooleanCheckbox value="#{connexionForm.isRemembered}" /> <h:outputText value="Se souvenir de moi" /> </p:panelGrid> <p:commandButton value="Connexion" id="doLogin" update="growl" action="connexionForm.authenticate" styleClass="ui-icon-login" /> </p:panelGrid> <p:commandLink id="forgetLogin" update="growl" actionListener="#{connexionForm.forgetLoginData}"> <h:outputText class="lien" value="Login ou mot de passe oublié" /> </p:commandLink> </h:form> </body> </f:view> </html>Merci d'avance pour votre aide
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 package ch.rwb.application.forms.login; import java.io.IOException; import javax.annotation.PostConstruct; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.RequestDispatcher; @ManagedBean @RequestScoped public class ConnexionForm { private String login; private String password; private boolean isRemembered; private String originalURL; /** * Default Constructor */ public ConnexionForm() { } @PostConstruct public void init() { ExternalContext externalContext = FacesContext.getCurrentInstance() .getExternalContext(); originalURL = (String) externalContext.getRequestMap().get( RequestDispatcher.FORWARD_REQUEST_URI); if (originalURL == null) { originalURL = externalContext.getRequestContextPath() + "/Accueil.xhtml"; } else { String originalQuery = (String) externalContext.getRequestMap() .get(RequestDispatcher.FORWARD_QUERY_STRING); if (originalQuery != null) { originalURL += "?" + originalQuery; } } } public String getLogin() { return login; } public String getPassword() { return password; } public boolean getIsRemembered() { return isRemembered; } public void authenticate() throws IOException { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); try { System.out.println("Username" + login); if("test".equals(login) && "passwd".equals(password)){ externalContext.getSessionMap().put("user", "john"); externalContext.redirect(originalURL); } throw new Exception("Invalid user/password"); } catch (Exception e) { context.addMessage(null, new FacesMessage("Unknown login")); } } }
Partager