Bonjour,

Il s'agit d'un exercice scolaire pour découvrir le fonctionnement des backing beans et la navigation dynamique via JSF.
Je dois faire un formulaire de login (username, password). En cas de succès de la méthode, je suis redirigé vers connexionOk.jsp. En cas, d'échec, je suis redirigé vers connexionKo.jsp

Lorsque, j'appuie sur le bouton "Login", rien ne se passe (la page identifiants.jsp est rechargée).

Voici mon fichier 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
 
<?xml version='1.0' encoding='UTF-8'?>
 
<!-- =========== FULL CONFIGURATION FILE ================================== -->
 
<faces-config version="2.1"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="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_1.xsd">
 
<navigation-rule>
    <from-view-id>/login.jsp</from-view-id>
    <navigation-case>
        <from-action>#{loginBean.login}</from-action>
        <from-outcome>succes</from-outcome>
        <to-view-id>/connexionOk.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{loginBean.login}</from-action>
        <from-outcome>echec</from-outcome>
        <to-view-id>/connexionKo.jsp</to-view-id>
    </navigation-case>
</navigation-rule>   
 
 
</faces-config>
web.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
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/welcomeJSF.jsp</welcome-file>
    </welcome-file-list>
</web-app>
Ensuite, LoginBean.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
 
package Bean;
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 
/**
 *
 * @author Swissboy
 */
@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean implements Serializable {
 
    private String username = null;
    private String password = null;       
 
    public LoginBean() {
    }
 
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
 
    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
 
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
 
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
 
    public String login() {
        if (username.equals("user") & password.equals("user")) {
            return "succes";
        }
        else {
            return "echec";
        }
    }
 
}
Enfin, ma page identifiants.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
29
30
31
32
 
<%-- 
    Document   : identifiants
    Created on : 8 mai 2013, 20:56:15
    Author     : Swissboy
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html>
<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <h:form id="formLogin">
 
                <h:outputLabel id="labelUsername" for="inputUsername" value="Username"/>
                <h:inputText id="inputUsername" required="true" value="#{loginBean.username}"/>     
 
                <h:outputLabel id="labelPassword" for="inputPassword" value="Password"/>
                <h:inputSecret id="inputPassword" required="true" value="#{loginBean.password}"/>
 
                <h:commandButton id="buttonLogin" type="submit" value="Login" action="#{loginBean.login}"/>
        </h:form>
 
    </body>
</html>
</f:view>