Saturday, 30 January 2016

Pass Username from login page to home page in Oracle ADF

Requirement: I have an application and in that application I have two views login.jsff and home.jsff. The login.jsff have an af:inputText component and an af:button component. The home.jsff will have an af:outputText and an af:link.

In login.jsff page when I type some value in the af:inputText and click on af:button (Login), it should navigate me to the home.jsff. In home.jsff the same value of the af:inputText as in login.jsff should be visible in the af:outputText in the home.jsff.

In home.jsff when I click on the af:link (Logout) it should navigate me back to the login.jsff.

Solution: For solution to the above requirement follow the steps as shown below:

Step 1: Create an Oracle ADF Fusion Web Application named as PassUnameFrmLoginToHomePg.

Step 2: In the ViewController project of our application create a Bounded Task Flow and name it as myTaskFlow.xml. In the myTaskFlow.xml drag and drop two view from the component palette and name it as login and home. Here login view should be the default view.

Drag and drop Control Flow Case from login view to home view and name it as doLogin.

Drag and drop Control Flow Case from home view to login view and name it as doLogout.

Step 3: Double click login view to create login.jsff. Similarly double click home view to create home.jsff.

Step 4: Open login.jsff. Drag and drop an af:inputText from the component palette and label it as label="Enter Username". Also create the binding of the af:inputText as binding="#{backingBeanScope.MyBean.unamebinding}".

Drag and drop af:button from the component palette and set the text as text="Login", action as action="doLogin" and actionListener as actionListener="#{backingBeanScope.MyBean.doLogin}"
Thus the complete login.jsff page code is shown below:

Step 5: Drag and drop af:outputText from the component palette and set the value as value="#{sessionScope.unamebinding}".

Drag and drop af:spacer from component palette and set width="200" height="10".

Drag and drop af:link from the component palette and set text="Logout" and action="doLogout".

Thus the complete home.jsff code is shown below:

Step 6: Create launch.jspx and drag and drop the Bounded Task Flow myTaskFlow.xml as a region. Thus the complete launch.jspx code is shown below:

Step 7: Save all and run the launch.jspx. Thus the ran application is shown below:

Step 8: Now Enter Username as Susanto and click on Login button

Thus the home.jsff is shown below. Here we can see that the same name Susanto is displayed in the af:outputText.

When I click on the Logout link it get navigated to login.jsff. as shown below:

Hence, the solution to our requirement.

If you like the post please comment, share and like me on Facebook.

Thanks & Regards,
Susanto Paul