Search This Blog

Saturday, March 19, 2016

07: OAF Displaying User Name, UserID, Responsibility

How to display User Name, User Id and Responsibility in OAF



In this lesson we are going to learn how to display Oracle Applications User Name, User Id, Responsibility Name and Responsibility Id.
We will see little bit java programming too in this chapter.
 
Steps to follow:
  1. Create a page first, see the chapter Welcome Page Creation to see how to create a page.
  2. Create the region and four items in the region, we can see the creation process of Regions and Items in previous chapter.
  3. Create the controller and write the Java Code.

Here I am taking the page which is already created and adding a region with region style as ” message Component Layout “.
After adding Region under region here we are creating four items and Item style of all the four items is ” message Text Input “.
After adding Region and Items the page structure will look like:

Displaying username and userid responsibility id in Oracle OAF

Now change the prompt values for each items as follows:
(if you want to know how to change the prompt values in the Property Inspector see the previous chapter which shows how to change the prompt value)
                    Prompt
item1  -> User ID
item2  -> User Name
item3  -> Responsibility ID
item4  -> Responsibility Name

The below picture shows how the output structure looks like after running the page, just have a look into it

Oracle Apps OAF  Displaying username userid responsibility name and responsibity id

Now we need to create a Controller, let us see how to create a controller in JDeveloper (OAF).
Best practice is to create the controller Globally so that it should be applicable to all the child regions.
Right Click on the Main Region and then select Set New Controller…

Controller in Oracle Apps OAF

After choosing Set New Controller, one dialog box window opens and it shows some default package and also some default name, in Package name at last generally we will find  “.webui.webui” change it to single webui i.e,. nothing but remove one webui from the default package name, for example assume the defualt pakcage is as follows:

newtonapples.oracle.apps.po.welcomeprj.webui.webui

change it to

newtonapples.oracle.apps.po.welcomeprj.webui

If you want to know why webui is there at end means you can see the BC4J file Structure lesson which displays the file structures.give the class name and we know that every controller ends with CO. For example give the controller name as WelcomeCO as shown below:

Oracle Apps OAF Controller

Click on OK button after giving Class Name and also after deleting one webui from the package. Now if you observe Applications Navigator structure controller is created under webui. Select the controller (WelcomeCO.java) and see the java program how it looks.

In the java program WelcomeCO class is created which is extending OAControllerImpl which contains main method.

We can also see two methods namely:

1) public void processRequest(OAPageContext pageContext, OAWebBean webBean)
the above method is used whenever we want any logic to be implemented before the page gets loaded. It means while loading a page if we want to display (or) perform any business logic then we go for processRequest.

2) public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
this method is used if we want any changes to be made once after the page gets loaded, i.e,. after the page is loaded suppose after clicking on particular button if we want to display the result into another item or after clicking on button if we want to go to another page.
As of now our requirement is to display the User ID, User Name, Responsibility ID, Responsibility Name whenever page gets loaded automatically all the fields to be displayed in the respective items. So therefore we need to write our program logic in the processRequest.
 
Oracle Apps OAF Controller Structure
Look at the below figure we declared four variables of type String and if you observe for number/id values we are just converting those values into the string. In the OAPageContext we will be having some defined values which we can access as shown in the below figure using notation dot (.) we will get all the available values and then we need to choose the required one.
Page Context in Oracle OAF pages
“pageContext” is nothing but the variable name of the OAPageContext (OracleApps page Context), if you observe to declared four variables we assigned values respectively.
Now after declaring variables and assigning values to the variables, we need to search for a items in our page, if you observe we created four items item1, item2, item3, and item4. So therefore to find the items in the page we need to use the bean as follows:
Here in this lesson we are not providing access to copy and paste the code of java, because whenever we are typing code JDeveloper prompts us to import the packages automatically. For example look at the below figure whenever we start typing, JDeveloper prompts us to click on Alt-Enter so that we can import the required package. It just saves our typing time of importing a package.
Automatic import in Oracle OAF Controller
After clicking on Alt-Enter it displays the packages list then choose the required import package. Here we are typing OAMessageTextInput it is a bean if you observe we used item style as “MessagetextInput” we are just adding OA (OracleApps) at the beginning and Bean at last which gives our Bean name. Now look at the below figure which shows the imported package name:
Automatically Imported Package in Oracle Apps OAF
Oracle Apps OAF Beans finding child recursive
If you observe first we initialized a bean and at the time of initialization we also need to import the respective package and hence now we know that how to import automatically the required package. After that declare a variable and we used java typecasting process here .
Every item has its own id so we used id value of the item to find the required item in the page.
Similarly write the code to find all the items in the page which we created.
Now after finding the items in the page we need to assign values which we got using pageContext into the respective items. It means we need to set a value for each item in the page and for that we use the line code as follows:
Oracle OAF setting values to the items
Similarly set values to all the items and after that the code looks like:
Oracle Apps OAF Program to display userid-username-responsibility id -responsibility name
Rebuild the program after finishing the code, just Right click on the code area and then select Rebuild option or we can also use a short cut code Alt+Shift+f9. Same scenario is shown in the below figure:
Compiling the controller in Oracle Apps OAF
After successfully rebuilding the java program Run the page and see the output. The output of the page which we created is as follows:
Output of the Oracle Apps JDeveloper

No comments:

Post a Comment