tags:

views:

39

answers:

2

When login page is loaded the input text box is displaying #{ad.userid}. When I erased it and entered id and pwd and clicked submit button the login method is called but userid property is giving null value in bean. How can this happen and how can I solve it?

Here is the login.jsp:

<%@ page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<html>

        <h:form>
            <h:outputText value="Login"/>
            <h:inputText value="#{ad.userid}" id="log" required="true"/>
            <h:outputText  value="Password" />
            <h:inputSecret id="pw" value="#{ad.password}" required="true"/>
            <h:commandButton  value="submit" action="#{ad.login}"/>
        </h:form>
    </body>
</html>
</f:view>

Here is the bean's action method. The login worked successfully earlier. All db connections are set in constructor.

public String login() {
    ResultSet rs;
    try {
        System.out.println(userid); // this is giving null
        String s = "select id from slogin where id='" + userid + "'";
        System.out.println(s);
        rs = st.executeQuery(s);
        if (rs.next()) {
            String loginid = rs.getString(1);
            if (userid.equals(loginid)) {
                id = loginid;
                return "studhome";
            }
        } else {
            System.out.println("error");
        }
    } catch(Exception e) {

    }
}

Getter and setter methods:

public void setpassword(String pass) {
    this.password = pass;
}

public String getpassword() {
    return password;
}

public void setuserid(String uid) {
    this.userid = uid;
}

public String getuserid() {
    return userid;
}
+1  A: 

Please, take your time to edit your question, format it properly using the formatting code tools that StackOverflow provides. The braces will appear if you use the button with the symbol "0101010101".

The answer:

Change:

public void setuserid(String uid)

to

public void setUserid(String uid)

and also:

public void setpassword(String pass)

to

public void setPassword(String pass)

Have a look at Java Naming Conventions, JSF relies on them to access the properties of a managed bean.

Btw, try to set your backing bean to Session scope to see if it works, to discard other problems

pakore
I didn't understand how to put < symbol in code.Anyway I changed the method names.but didn't work.the problem was not with names.I have run it successfully earlier with old names.I put some jfree chart jar filesin apache/lib/ for getting graphs.I did some changes to classpath also.I got errors from then.I removed all those changes but not getting the normal execution as earlier.
john
See my update at the bottom of the answer.
pakore
A: 

I am not sure if this is helpful - 1) add debug(sysouts) statements in the getters and setters and use the naming conventions as said by pakore (better you can ask eclipse to generate getters and setters).

2) try to write a Phaselistener to see if all the apply request and update model phases of jsf life cycle happens.

gurupriyan.e