Question

How would I implement a login page using JSF? At the moment I have a registration form which stores the values in a variable in a Java Bean.
I now need to create a log in and log out page for this. How would I go about on achieving this ?

Here is the code for the bean :

public String checkValidUser(String name) {
    dbData(name);
    if(name.equalsIgnoreCase(dbUsername)) {
        if(password.equals(dbPassword)) {
            return "success.xhtml";
        }
        else {
            return "fail.xhtml";
        }
    }
    else {
        return "fail.xhtml";
    }
}

This is the LogIn Page :

            <h:outputText value="Forename"/>
            <h:inputText  id="forename" size="25" maxlength="30" required="true" 
                          requiredMessage="Please Enter Your Forename" 
                          validatorMessage="FR ERR" 
                          value="#{databaseLoginReg.name}">
                <f:validateLength maximum="30" minimum="1"/>
            </h:inputText>
            <h:message errorClass="error" for="forename"/>


            <h:outputText  value="Enter Password"/>
            <h:inputSecret id="password" size="25" maxlength="16" required="true"
                           requiredMessage="Please Enter a Password"
                           validatorMessage="ERR"
                           value="#{databaseLoginReg.password}">
                <f:validateLength maximum="16" minimum="8"/>
            </h:inputSecret>
            <h:message errorClass="error" for="password" />


            <h:commandButton value="Log In" action="{databaseLoginReg.checkValidUser}"/>

The error:

javax.el.MethodNotFoundException: /logIn.xhtml @47,94 action="#{databaseLoginReg.checkValidUser}": Method not found: databaseLoginReg@77ff927f.checkValidUser()
Was it helpful?

Solution

The method's signature in the managed-Bean (with 1 String parameter) is different of the used in the view (without any parameters). That's why the JSF triggered the exception.
You should unify the method's signatures to enable its use through the view, for example, remove the parameter of the method public String checkValidUser(){ ... } while you can get the name and password easily in the managed-bean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top