Cannot set class fields using textInput
when the validation function for a user's login runs, the username and password fields are null. i have written the code according to many examples that i have seen on the internet. please help me understand why these fields are not being set.
also, when i run this app in a browser, the fields literally say #{Login.username}, and #{Login.password} instead of being blank like in other people's examples and tutorials. i assume it is a symptom of the problem here.
thanks in advance
Code :
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
<faces-config>
<managed-bean>
<managed-bean-name>Login</managed-bean-name>
<managed-bean-class>Security.Login</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/Login.jsp</from-view-id>
<navigation-case>
<from-action>#{Login.ValidateLogin}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/LoginValid.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{Login.ValidateLogin}</from-action>
<from-outcome>failure</from-outcome>
<to-view-id>/LoginInvalid.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>JSP Page</title>
</head>
<body>
<h:form>
<table>
<tr>
<td><h:outputText value="Username: "/></td>
<td><h:inputText id="username" required="true" value="#{Login.username}" /></td>
</tr>
<tr>
<td><h:outputText value="Password: "/></td>
<td><h:inputText id="password" required="true" value="#{Login.password}"/></td>
</tr>
<tr>
<td> </td>
<td><h:commandButton value="login" action="#{Login.ValidateLogin}"/></td>
</tr>
</table>
</h:form>
</body>
</html>
</f:view>
package Security;
public class Login {
private String username;
private String password;
public Login() {} // Inline Constructor for Login class
public void setUsername(String username) { this.username = username; }
public void setPassword(String password) { this.password = password; }
public String ValidateLogin() {
if("ianmcdavid".equals(username) && "cole".equals(password)) {
return "success";
}
else {
return "failure";
}
}
}