In this exercise we will create two page one login page and one home page.
Once we will enter the correct user id and password the page will redirect
My login page will look like this.
On Successful login the page will redirect to my home page.
On un successful login i will get an error message.
The login page and the home page are build in simple jsp using panel stretch layout and panel group layout.
Have created binding for username , password and outcome parameter in the managed bean.
Following is the code for the action button
public String cb1_action() {
// Add event code here...
RichInputText userText = getUsername();
RichInputText pwdText = getPassword();
String in = userText.getValue().toString();
String op = pwdText.getValue().toString();
String value = "Invalid credentials!!";
String value1 = "Login Successful!!";
System.out.println("test1");
System.out.println(in);
System.out.println(op);
//RichInputText resultText = getPassword();
if (in.equalsIgnoreCase(op)) {
System.out.println("test2");
outcome.setValue(value1);
return "success";
} else {
System.out.println("test2");
outcome.setValue(value);
}
return null;
}
Here as you can see in case of a success (which in my case isboth user and pwd are same) i am also returning a success.
This is because in my faces-config.xml the redirection input is set as success
Now with this base you can use your own coding style for validating user/pwd.
No comments:
Post a Comment