Sun. Oct 24th, 2021

Requirement: I have four fragments: login.jsff, admin.jsff, setting.jsff, and user.jsff. On the login.jsff I have three components: Select User Type with two values as Administrator and User. Then, I have field for User Name and a field for Password which is secret. Then I have a Login button

If I select User Type as Administrator and give the corresponding User Name and Password and click on Login, then, it should redirect to the admin.jsff. In admin.jsff the User Type text, Setting link, and the Logout link will be in the header of the admin.jsff. On click of Logout link it should go back to the login.jsff page again. On click of the Setting link it will go to the setting.jsff.

If I select User Type as User and give the corresponding User Name and Password and click on Login, then, it should redirect to the user.jsff. In user.jsff the User Type text and the Logout link will be in the header of the user.jsff. On click of Logout link it should go back to the login.jsff page again.

Now, if the User Type is Administrator and we are on admin.jsff then one more link that is Setting link has to be visible in the header of that page. The Setting link will enable us to go to the setting.jsff.

Now, if the User Type is Administrator and we are on setting.jsff then one more link that is Admin link has to be visible in the header of that setting.jsff page. The Admin link will enable us to go to the admin.jsff.

Now, if the User Type is User then both the links Setting and Admin should not be there, as User is not allowed to access those pages.

For reference the login.jsff page will look as shown below:

The admin.jsff will look like as shown below:

The setting.jsff will look like as shown below:

The user.jsff will look like as shown below:

Thus, if the User Type is Administrator then the display page is shown below:

If the User Type is User then the display page is shown below:

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

Step 1: Create an Oracle ADF Fusion Web Application. Name the application as: MethodCallTaskflowReturn.

Step 2: Create four Bounded Taskflows: adminBTF, settingBTF, userBTF, and loginBTF as shown below:

Step 3: Open adminBTF. Drag and drop View from the component palette. Name the View as admin. Double click on the admin view and create the admin.jsff fragments as shown below: The Document Type should be JSP XML.

Step 4: Open adminBTF. Drag and drop View from the component palette. Name the View as admin. Double click on the admin view and create the admin.jsff fragments as shown below: The Document Type should be JSP XML.

Drag and drop three taskFlowReturn activities from the component palette on the adminBTF. Name the three taskFlowReturn activities as: back, gotoUser, and gotoSetting. Set the id of the three taskFlowReturn as: taskFlowReturn1, taskFlowReturn2, and taskFlowReturn3 as shown below:

Now drag and drop three Control Flow Case from the component palette on the adminBTF. Name the three Control Flow Case as: back, gotoUser, and gotoSetting. Thus the complete adminBTF will look like as shown below:

Step 5: Open userBTF. Drag and drop View from the component palette. Name the View as user. Double click on the user view and create the user.jsff fragments as shown below: The Document Type should be JSP XML.

Drag and drop three taskFlowReturn activities from the component palette on the userBTF. Name the three taskFlowReturn activities as: back, gotoAdmin, and gotoSetting. Set the id of the three taskFlowReturn as: taskFlowReturn1, taskFlowReturn2, and taskFlowReturn3 as shown below:

Step 6: Open settingBTF. Drag and drop View from the component palette. Name the View as setting. Double click on the setting view and create the setting.jsff fragments as shown below: The Document Type should be JSP XML.

Drag and drop four taskFlowReturn activities from the component palette on the settingBTF. Name the three taskFlowReturn activities as: back, gotoAdmin, gotoUser and gotoSetting. Set the id of the three taskFlowReturn as:

Step 7: Open loginBTF. Drag and drop View from the component palette. Name the View as login. Double click on the login view and create the login.jsff fragments as shown below: The Document Type should be JSP XML. Design the flow as shown below:

Please note here we have drag and drop Method Call Activity named as doLogin from the component palette. It is place where we will write the logic to redirect on the page based on the supplied credentials like User Type, User Name and Password.

Step 8: Create a Java class named as MyBean.java and write the below code there:

package com.susanto;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpSession;

import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.input.RichSelectOneRadio;

import org.apache.myfaces.trinidad.util.ComponentReference;

public class LoginBean {
    private String decision;
    private ComponentReference utype;
    private ComponentReference uname;
    private ComponentReference pwd;

    public LoginBean() {
    }

    public String doLoginDecision() {
        String admin_username = "Susanto";
        String user_username = "Moumita";
        String admin_password = "welcome1";
        String user_password = "welcome2";
        String userType = (String) getUtype().getValue();
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpSession httpSession = (HttpSession) externalContext.getSession(true);
        httpSession.setAttribute("uname", getUname().getValue());
        String userName = (String) getUname().getValue();
        String userPwd = (String) getPwd().getValue();
        if (userType.equals("Administrator")) {
            if (userName.equals(admin_username) && userPwd.equals(admin_password)) {
                return "gotoAdmin";
            }
        } else if (userType.equals("User")) {
            if (userName.equals(user_username) && userPwd.equals(user_password)) {
                return "gotoUser";
            }
        }
        return "";
    }

    public String getDecision() {
        return decision;
    }

    public void setDecision(String decision) {
        this.decision = decision;
    }

    public void setUname(RichInputText uname) {
        this.uname = ComponentReference.newUIComponentReference(uname);
    }

    public RichInputText getUname() {
        return uname == null ? null : (RichInputText) uname.getComponent();
    }

    public void setPwd(RichInputText pwd) {
        this.pwd = ComponentReference.newUIComponentReference(pwd);
    }

    public RichInputText getPwd() {
        return pwd == null ? null : (RichInputText) pwd.getComponent();
    }

    public void setUtype(RichSelectOneRadio utype) {
        this.utype = ComponentReference.newUIComponentReference(utype);
    }

    public RichSelectOneRadio getUtype() {
        return utype == null ? null : (RichSelectOneRadio) utype.getComponent();
    }
}

Step 9: Now open loginBTF and select doLogin Method Call Activity and set the method as #{pageFlowScope.LoginBean.doLoginDecision}. Also set the toString() as true as shown below:

Step 10: In the MyBean.java class I have also captured the uname in sessionScope by writing the below line of codes inside doLoginDecision method. This will allow us to use the uname throughout the session in any places.

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpSession httpSession = (HttpSession) externalContext.getSession(true);
        httpSession.setAttribute("uname", getUname().getValue());

Step 11: Now go to the login.jsff and design the page as shown below:

The code for the above login.jsff is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1" xmlns:af="">
    <af:selectOneRadio label="Select User Type" id="sor1" layout="horizontal"
                       binding="#{pageFlowScope.LoginBean.utype}">
        <af:selectItem label="Administrator" value="Administrator" id="si1"/>
        <af:selectItem label="User" value="User" id="si2"/>
    </af:selectOneRadio>
    <af:inputText label="User Name" id="it1" binding="#{pageFlowScope.LoginBean.uname}"/>
    <af:inputText label="Password" id="it2" binding="#{pageFlowScope.LoginBean.pwd}" secret="true"/>
    <af:button text="Login" id="b1" action="gotoDoLogin"/>
</jsp:root>

Step 12: Now go to the admin.jsff and design the page as shown below:

The code for the above admin.jsff is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1" xmlns:af="">
    <af:outputFormatted value="Admin Page" id="of1"/>
    <af:spacer width="700" height="10" id="s1"/>
    <af:activeOutputText id="aot1" inlineStyle="font-size:small;" value="#{sessionScope.uname}"/>
    <af:spacer width="10" height="10" id="s2"/>
    <af:link text="Goto User Page" id="l1" action="gotoUser"/>
    <af:spacer width="10" height="10" id="s4"/>
    <af:link text="Goto Setting Page" id="l2" action="gotoSetting"/>
    <af:spacer width="10" height="10" id="s3"/>
    <af:link text="Logout" id="l3" action="back"/>
</jsp:root>

Step 13: Now go to the setting.jsff and design the page as shown below:

The code for the above setting.jsff is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1" xmlns:af="">
    <af:outputFormatted value="Setting Page" id="of1"/>
    <af:spacer width="700" height="10" id="s1"/>
    <af:activeOutputText id="aot1" inlineStyle="font-size:small;" value="#{sessionScope.uname}"/>
    <af:spacer width="10" height="10" id="s2"/>
    <af:link text="Goto User Page" id="l1" action="gotoUser"/>
    <af:spacer width="10" height="10" id="s4"/>
    <af:link text="Goto Admin Page" id="l2" action="gotoAdmin"/>
    <af:spacer width="10" height="10" id="s3"/>
    <af:link text="Logout" id="l3" action="back"/>
</jsp:root>

Step 14: The code for the user.jsff is shown below:

<jsp:root xmlns:jsp="" version="2.1" xmlns:af="">
    <af:outputFormatted value="User Page" id="of1"/>
    <af:spacer width="700" height="10" id="s1"/>
    <af:activeOutputText id="aot1" inlineStyle="font-size:small;" value="#{sessionScope.uname}"/>
    <af:spacer width="13" height="10" id="s4"/>
    <af:link text="Goto Admin Page" id="l1" action="gotoAdmin" rendered="#{sessionScope.uname=='Susanto'}"/>
    <af:spacer width="10" height="10" id="s2"/>
    <af:link text="Goto Setting Page" id="l2" action="gotoSetting" rendered="#{sessionScope.uname=='Susanto'}"/>
    <af:spacer width="10" height="10" id="s3"/>
    <af:link text="Logout" id="l3" action="back"/>
</jsp:root>

Thus, if the User Type is Administrator then the display page is shown below:

If the User Type is User then the display page is shown below:

Hence, the solution to our requirement.

If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.

Thanks & Regards,
Susanto Paul

 551 total views,  2 views today

By Susanto Paul

Susanto is an Oracle ACE, a qualified MCA, MBA, and a highly-skilled Senior Oracle Specialist. He is an enthusiastic Blogger and YouTuber who helps learners to solve their complex problems more efficiently. He has 9+ years of experience in multiple technologies like AWS, Oracle ADF, Oracle APEX, Oracle JET, Oracle VBCS, Oracle IDCS, Oracle PL/SQL, Oracle Integration Cloud, Java, JDBC, Servlets, JSP, Spring, Hibernate, HTML5, CSS3, JavaScript, TypeScript, NodesJS, Angular, MySQL, Oracle WebLogic Server, JUnit, JMeter, Selenium Web Driver, etc. He is a certified: Oracle Certified Professional Java SE 6 Programmer, Oracle ADF 11g Certified Implementation Specialist, Oracle Cloud Platform Application Integration 2020 Certified Specialist, Oracle Cloud Infrastructure Foundations 2020 Certified Associate, and Oracle Cloud Infrastructure Developer 2020 Certified Associate

Leave a Reply

Your email address will not be published. Required fields are marked *

satta king chart