views:

639

answers:

2

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"%&gt;
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%&gt;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"&gt;

<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>
+1  A: 

I don't know much about requested beans. Have u tried to change it for session bean ? My guess is that those beans need some initialization which your code lacks.

Dogrizz
Thats was not the problem, anyways thanks for trying to help.
Dmitris
+2  A: 

This is probably the problem:

<f:validator validatorId="Login" />

Remove the tag.

The validatorId attribute value must correspond to the validator-id element of a Validator registered in faces-config.xml.

McDowell
I found the solution, and what you said was exactly the problem.Took me entire day to figure it out, i wish they would do java error messages more verbose.Anyways, thank you very much!
Dmitris