Log in functionality in ADF application

Requirement: Log in to ADF application and navigate to Admin / Customer pages based on type of user logs in.

This can be done in many ways. Here i’m giving one way of achieving the requirement.

1) First create a jspx page and don’t forget to select ‘Automatically Expose UI Components in a new Managed Bean’ while creating the page. Now a java class is also created automatically which holds the bindings of the page which we created earlier.

2) Now drag and drop the Input Text (ADF Faces.Common Components) two times for username and password fields. And also Drag and drop a Button (ADF Faces.Common Components) for Log in button.

login1

3) Now create the task flows from current log in page to Admin and Customer pages in faces-config.xml file by giving proper path names to the flows.

taskflows

-> // Logic is get the user entered input username value and compare with the required value and Navigate to the respective pages by calling respective task flow with path name (action name) //

4) Now bind the username input field value to a String in backing bean java class and set the autoSubmit property to true

<af:inputText label=”Username” autoSubmit=”true” value=”#{backingBeanScope.backing_oracle_webcenter_portalapp_pages_test.username}”
                            binding=”#{backingBeanScope.backing_oracle_webcenter_portalapp_pages_test.it1}”
                            id=”it1″/>

5) Create a String with name as username and generate accessors for it.

6)for  Calling  a java method after clicking on button give action as

action = “{backingBeanScope.backing_oracle_webcenter_portalapp_pages_test.validateLogin”

create the method validateLogin in the bean and write the logic in that method.

login_java

Session Scope in ADF

If you want to display the text entered in the current page in other pages, it is simpler to do it by using of Session Scope variable.

A Sample Code is given below

Current Page Code: <af:inputText value=”#{sessionScope.ravi}” label=”EmailID:” autoSubmit=”true” /> 

input

Here what ever the user enters as input will store into Session Scope Variable ‘ravi‘ , which can be used in any other pages and even in java class too.

Code to display the entered string stored in Session Scope  <af:outputText value=”#{sessionScope.ravi}”/>

output

You can Access the Session Scope variable in Java class using below given sample code:

String sessvalue = ADFContext.getCurrent().getSessionScope().get(“ravi”).toString();

java