Hello everybody. I really need help on this one.
I am having a simple login form in jsp file, and i try to use JSF and managed beans with it. When i first fire page it is displaying it content, however when push the submit button (h:commandButton) i am getting an error.
Can somebody tell me what is wrong with my code ?
error:
javax.servlet.ServletException: javax.faces.FacesException: Expression Error: Named Object: Login not found.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
Here is my JSP:
<%@page contentType="text/html"%>
<%@page 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h:form id="login">
<h:messages tooltip="true" />
<h:inputText id="userNaME" required="true" requiredMessage="User name is required" value="#{Login.userName}" >
<f:validator validatorId="Login" />
</h:inputText><br />
<h:inputSecret id="userPassword" required="true" value="#{Login.userPassword}" requiredMessage="User Password is required" /><br />
<h:commandButton id="Login" title="Login" type="submit" action="#{Login.LoginUser}" />
<h:message for="Login" style="color: green;" />
</h:form>
</body>
</html>
</f:view>
My Bean Class:
package myvalidators;
public class Login {
private String _userName;
private String _userPassword;
public void setUserName(String userName)
{
this._userName = userName;
}
public String getUserName()
{
return this._userName;
}
public void setUserPassword(String userPassword)
{
this._userPassword = userPassword;
}
public String getUserPassword()
{
return this._userPassword;
}
public String LoginUser()
{
return this._userName;
//going to perform a login here
}
}
And my faces-config xml
<managed-bean>
<managed-bean-name>Login</managed-bean-name>
<managed-bean-class>myvalidators.Login</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>