Sunday, May 10, 2009

How to create Login page in ADF

I am using the employee table in HR schema , where I am using the employee first name as the user name and the employee last name as the password. We will create three jsf pages. On valid user name password user will navigate to success page and on error it will navigate to failure page

Step 1) Create a read only View Object with bind variable with name EmpLoginViewObj. Following is the SQL query:-
SELECT
EMPLOYEES.EMPLOYEE_ID EMPLOYEE_ID,
EMPLOYEES.FIRST_NAME FIRST_NAME,
EMPLOYEES.LAST_NAME LAST_NAME
FROM
EMPLOYEES
WHERE EMPLOYEES.LAST_NAME =:LastName

Create the bind variable with name LastName. Make sue that you are generating the ViewObjImpl class for the above created view object.

Step 2) Add the above created View object in the Application module.

Step 3) Add the following code in the application module's Java Impl class

public void checkLoginCredentials(String ename,String pwd_form)
{
System.out.println(ename + " " + pwd_form);
EmpLoginViewObjImpl vo = (EmpLoginViewObjImpl)getEmpLoginViewObj1();
//set the bind variable value to last name
vo.setNamedWhereClauseParam("LastName",pwd_form);
vo.executeQuery();
int rowCount=vo.getEstimatedRangePageCount();
System.out.println("rowCount="+rowCount);
if(rowCount==0) {
throw new JboException("Password doesn't match");
}
}

Import oracle.jbo.JboException class in the AMImpl class.

Step 4) Expose the above method in the Client Interface of the application module.
Now the method checkLoginCredentials will appear in the data control palette.

Step 5) Create three jspx pages. LoginPage.jspx, WelcomePage.jspx and FaliurePage.jspx

Step 6) Drag and drop the checkLoginCredentials on your LoginPage.jspx page as the parameter->ADF parameter Form.

Step 7) Double click the command button on LoginPgae.jspx and define a new action binding by first defining the managed bean(with Name backing_LoginPage) and action binding method name as loginBtn_action()

Step 8) Add the following code inside your loginBtn_action() method.

public String commandButton_action() ()
{
String returnStr="error";
System.out.println("Inside loginBtn_action");
BindingContainer bindings = getBindings();
OperationBinding operationBinding =
bindings.getOperationBinding("checkLoginCredentails");
Object result = operationBinding.execute();
System.out.println(result);
if (operationBinding.getErrors().isEmpty()) {
returnStr= "success";
}
System.out.println("returnStr= " + returnStr);
return returnStr;
}

Step 8 ) Set the navigation rule as

/LoginPage.jspx

#{backing_LoginPage.commandButton_action}
success
/WelcomePage.jspx


#{backing_LoginPage.commandButton_action}
error
/FaliurePage.jspx




run your login page to check the results.

0 comments: