You are on page 1of 30

Build simple search page in OA Framework

Here are the steps to create a simple search page in OA Framwork. I have used OAF Version
12.1.1 for this exercise. There are many ways to do this and here I have followed one of these.
Step 1: Create a Package
All BC4J model components must belong to a Business Components (BC4J) package. So create
a package with a name like xxhci.oracle.apps.custom.LabExamples.server.

Step2: Create an Entity Object (EO)


Entity objects encapsulate business logic and DML operations for application tables.

To create a new entity object in the above defined Business Components (BC4J) package:
1. In the JDeveloper Navigator, select the BC4J package where you want to create your entity
object.
2. Right click and select New Entity Object
3. Do the following steps to create an EO.

2.1 Specify a Schema Object (the exact name of the table for the entity object)

2.2 In the Attributes page (Step 2 of 5), you should see all the columns in the table that you
specified in the Name page.

Select New to create a transient attribute that is used in the business logic, such as a calculated
OrderTotal in a purchase order that is used for approval checking.
2.3 In the Attribute Settings page (Step 3 of 5), verify or set the following information for each
of the entity objects attributes:

The Attribute and Database Column Name and Type properties default correctly from the table
definition. For primary key columns, ensure that the Primary Key and Mandatory checkboxes are
selected. For columns that are never updateable, or updateable only when new, select the
appropriate Updateable radio button. For columns whose values change after database triggers
execute, select the Refresh After update or insert as appropriate.
2.4 In the Java page (Step 4 of 5) page:
Check the option for generating an Entity Object Class. In the Generate Methods box, opt
to generate Accessors, a Create Method and a Remove Method.

2.5 Click on Generate default view object to create a VO. Select Finish to save your entity
object definition and implementation. BC4J will create an XML definition file and a Java
implementation file for your entity object.

Step3: Create an View Object (VO)


If you click Generate default view object tab as mentioned above, you dont have to create a
VO separately. If you forgot this, you have to create a VO. Click on the VO to test the SQL
Statement generated by the EO and check in the Expert Mode.

Step4: Create a New Application Module (AM)


To create a new application module in a Business Components (BC4J) package:
1. In the JDeveloper Navigator, select the BC4J package where you want to create your
application module.
2. From the main menu, choose File > New to open the New Object Gallery.

Select the view object.

In the Java page (Step 4 of 5), deselect the Generate Java File(s) checkbox ONLY if you are
certain that you wont be writing any code for your application module (you can always delete
the class later if you find that you dont need it, so its probably best to simply generate it at this
point unless you are creating a simple container for LOV view objects).

Select Finish to create your application module. BC4J will create an XML definition and
implementation file.
Step5: Create a Page (EmpSearchPG)
Create the EmpSearchPG page as follows
Right click on project New Web Tier OA Components Page
Give the Page Name as EmpSearchPG and package as
xxhci.oracle.apps.custom.LabExamples.webui
Select region1 page from Structure Window and change its properties as
ID PageLayoutRN
Select the AM Definition as
xxhci.oracle.apps.custom.LabExamples.server.XxhciOafTrngEmpTabAM
Give a Window Title as Employees Search Window
Give a Title as Employees

Step6: Add a Query region and Results table


Right click on PageLayoutRN New Region. Set the properties of the new region as
ID QueryRN
Select the Region Style as query and Construction Mode as resultBasedSearch.
Right click on QueryRN region on structure navigator New Region using wizard.
Select the AM and VO which we have created in earlier steps as shown in below figure.

Set the Region Style as Table

Change the Prompt and Style for all three items.

Step7: Changes the Item Properties

Go to EmpNo item and set the Search Allowed property to true. Similarly do the steps for
EmpName and Department also.

Step8: Save all changes (Save All).


Step9: Run the Page (EmpSearchPG)
Creation of search page is complete. Run the EmpSearchPG to test the page. If everything works
fine for you, you should able to view an output like below:

Few Note:
Understanding Query Regions
When you add a query region to a pageLayout region, OA Framework automatically generates
an oracle.apps.fnd.framework.webui.beans.layout.OAQueryBean which, depending on its
configuration, works in concert with a child table, advanced table or HGrid to implement any
combination of simple search, advanced search and view panels. OA Framework automatically
generates buttons as appropriate for toggling between the applicable regions.
Construction Modes:
There are three construction modes available. In the above example we have used
resultBasedSearch construction mode. Here is a brief comparison of the three modes.
1] resultsBasedSearch:
OA Framework automatically renders both the Simple and Advanced search regions
based on the designated queryable items in the associated table.
The search regions automatically include both a Go and a Clear button.
OA Framework automatically executes the underlying search when the user selects the
Go button.

2] autoCustomizationCriteria:
OA Framework automatically renders both the Simple and Advanced search regions
based on the corresponding Simple search and Advanced search regions that you define
and specify as named children of the query region.
The search regions automatically include a Go button. In addition, the Advanced search
region includes a Clear button.
OA Framework automatically executes the underlying search when the user selects the
Go button. However, developers must explicitly define mappings between items in the
Search panel and items in the table region.
3] none
The Search regions are rendered based on the Simple Search and Advanced Search
regions that you define and specify as named children of the query region.
You must implement your own Go button in this mode.
The underlying search must be executed by the developer.

Here I am posting a step by step tutorial to build a simple CREATE page in OAF. It is a
continuation of an earlier tutorial and so you need to go through that first before going through
this.
Here is the link: Build Simple Search Page in OAF
Step1: Build a Create Button
Select the view EmpSearchPG, right click and select New > TableActions. One region
(region1) will be created with region style as FlowLayout.
Change the ID of the above newly created region to ButtonLayoutRN.
Right click ButtonLayoutRN and create a new Item.
Set the below details for the Item
o ID :Create
o Item Style : submitButton
o Attribute Set:
/oracle/apps/fnd/framework/toolbox/attributesets/FwkTbxEmployees/CreateEmpl
oyee
o Action Type: fireAction
o Event: create

Step 2: Set a Controller

Right click PageLayoutRN and select Set New Controller.


Give the package name as xxhci.oracle.apps.custom.LabExamples.webui.
Give the class name as EmpSearchCO.

Add the following logic to processFormRequest of EmpSearchCO.java after


super.processFormRequest method.
view source

print?

1 if (pageContext.getParameter("event").equalsIgnoreCase("create")) {
2 System.out.println("EmpSearchCO: processing create/update");
pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/custom/LabExamples
/webui/EmployeeCreatePG",
4 null,
3

5 OAWebBeanConstants.KEEP_MENU_CONTEXT,
6 null, null, true,
7 OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
8 OAWebBeanConstants.IGNORE_MESSAGES);
9}

You might get red lines under java classes which are not imported. Bring the cursor on these redlined text and click Alt+Enter (JDev automatically tells you to import the class using Alt+Enter
when you move cursor over these lines).
Step 3: Build the Create Employee Page (EmployeeCreatePG)
Right click on Project >New >Web Tier >OA Components Page.
Set the Page name as EmployeeCreatePG
Set the package name as xxhci.oracle.apps.custom.LabExamples.webui

Select the pageLayout region of EmployeePG and assign the properties as below
ID : PageLayoutRN
AM Definition :
xxhci.oracle.apps.custom.LabExamples.server.XxhciOafTrngEmpTabAM
Window Title : Employee Window
Title: Employee
Warn About Change: True

Step 4: Add items to Create Employee Page

Create a region under PageLayoutRN and assign ID as PageButtonsRN.


Set the region style as pageButtonBar
Now we need to create two buttons in this region as APPLY and CANCEL.

For Apply Button:


Right click on PageButtonsRN > New > Item.
Set the properties as
ID :Apply
Item Style :submitButton
Attribute Set : /oracle/apps/fnd/attributesets/Buttons/Apply
Additional Text :Click to save the transaction
Action Type: fireAction
Event: Apply
For Cancel Button:
Right click on PageButtonsRN > New > Item.
Set the properties as
ID : Cancel
Item Style : submitButton
Attribute Set :/oracle/apps/fnd/attributesets/Buttons/Cancel
Additional Text : Click to cancel the transaction
Action Type: fireAction
Event: Cancel

For text items in page: Right click on PageLayoutRN New Region using wizard. Enter data
as shown in below screenshots
Step 4.1: Select AM and VO instance created during search page

Step 4.2: Give Region ID as MainRN and Region Style as defaultSingleColumn

Step 4.3: Select attributes as below (EmpNo, EmpName and Department)

Step 4.4: Change the prompts of items as shown below (messageInputText)

Click on finish for step 5.


Change the Region Style for MainRN to messageComponentLayout. This is done now as
above region wizard, doesnt have support for messageComponentLayout. Click on Yes button
when the confirm window pops for change of region style.
Step5: Adding Model Layer Code
Add following code to XxhciOafTrngEmpTabAMImpl.java. Add import statements at the
start and rest of the methods with the class definition.
view source

print?

01 import oracle.jbo.Row;
02 import oracle.apps.fnd.framework.OAViewObject;
03 import oracle.jbo.Transaction;
04 import oracle.jbo.domain.Number;
05 import oracle.jbo.RowSetIterator;
06

07

// Creates a new employee.

08
09
10

public void createEmployee()


{

11
12

OAViewObject vo = (OAViewObject)getXxhciOafTrngEmpTabEOView1();
// Per the coding standards, this is the proper way to initialize a

13
14

// VO that is used for both inserts and queries. See View Objects
// in Detail in the Developer's Guide for additional information.

15
16

if (!vo.isPreparedForExecution())
{

17
18

vo.executeQuery();
}

19
20

Row row = vo.createRow();


vo.insertRow(row);

21
22

// Required per OA Framework Model Coding Standard M69


row.setNewRowState(Row.STATUS_INITIALIZED);

23

} // end createEmployee()

24
25

// Executes a rollback including the database and the middle tier.

26
27
28

public void rollbackEmployee()


{

29

Transaction txn = getTransaction();


// This small optimization ensures that we don't perform a

30

rollback

31
32

// if we don't have to.


if (txn.isDirty())

33
34

{
txn.rollback();

35
36

}
}

37
38

//Commits the transaction.

39
40

public void apply()

41
42

{
getTransaction().commit();

43

Add the following import statement and modify the create method in
XxhciOafTrngEmpTabEOImpl as follows:

Add this as a part of import statements


view source

print?

1 import oracle.apps.fnd.framework.server.OADBTransaction;

Modify the create method as below


view source

print?

1 public void create(AttributeList attributeList) {


2
super.create(attributeList);
3
4

OADBTransaction transaction = getOADBTransaction();


Number employeeId = transaction.getSequenceValue("FWK_TBX_EMPLOYEES_S");

5
6}

setEmpNo(employeeId.toString());

Step6: Add Controller logic for Create Employee Page


Right click on PageLayoutRN of EmployeeCreatePG > Set New Controller.
Give the values as
Package : xxhci.oracle.apps.custom.LabExamples.webui
Class Name : EmployeeCO
Add the below code to the new CO
Import Statements:
view source

print?

1 import java.io.Serializable;
2 import oracle.apps.fnd.common.MessageToken;
3 import oracle.apps.fnd.framework.OAApplicationModule;
4 import oracle.apps.fnd.framework.OAException;
5 import oracle.apps.fnd.framework.OAViewObject;
6 import oracle.apps.fnd.framework.webui.OADialogPage;
7 import oracle.apps.fnd.framework.webui.OAWebBeanConstants;

processRequest (after super.processRequest):


view source

print?

01 if (!pageContext.isBackNavigationFired(false)) {
02
OAApplicationModule am =
03
04

pageContext.getApplicationModule(webBean);
am.invokeMethod("createEmployee");

05 } else {
06
// We got here through some use of the browser "Back" button, so we
07
08

// want to display a stale data error and disallow access to the


OADialogPage dialogPage = new OADialogPage(STATE_LOSS_ERROR);

09
10 }

pageContext.redirectToDialogPage(dialogPage);

processFormRequest (after super.processFormRequest):


view source

print?

01 OAApplicationModule am = pageContext.getApplicationModule(webBean);
// Pressing the "Apply" button means the transaction should be
02
validated
03
// and committed.
04 if (pageContext.getParameter("event").equalsIgnoreCase("Apply")) {
0
5
0
6 );

OAViewObject vo =
(OAViewObject)am.findViewObject("XxhciOafTrngEmpTabEOView1"

07
08

String employeeName =
(String)vo.getCurrentRow().getAttribute("EmpName");

09
10

String employeeNum =
(String)vo.getCurrentRow().getAttribute("EmpNo");

11
12

am.invokeMethod("apply");
MessageToken[] tokens =

13
14

{ new MessageToken("EMP_NAME", employeeName),


new MessageToken("EMP_NUMBER", employeeNum) };

15

OAException confirmMessage =
new OAException("AK", "FWK_TBX_T_EMP_CREATE_CONFIRM",

16
17

tokens,
OAException.CONFIRMATION, null);

18

pageContext.putDialogMessage(confirmMessage);

1
pageContext.forwardImmediately("OA.jsp?page=/xxhci/oracle/ap
9 ps/custom/labExamples/webui/EmpSearchPG",
2
null,
0
2
1 _CONTEXT,
22

OAWebBeanConstants.KEEP_MENU

2
3 _CRUMB_NO);
24
}

OAWebBeanConstants.ADD_BREAD

null, null, true,

25 // If Cancel button is pressed, rollback the transaction


26 else if (pageContext.getParameter("event").equalsIgnoreCase("Cancel")) {
2
am.invokeMethod("rollbackEmployee");
7
2
pageContext.forwardImmediately("OA.jsp?page=/xxhci/oracle/ap
8 ps/custom/labExamples/webui/EmpSearchPG",
29
3
0 _CONTEXT,

null,
OAWebBeanConstants.KEEP_MENU

31
3
2 _CRUMB_NO);

null, null, false,


OAWebBeanConstants.ADD_BREAD

33

Step 7: Save all and Run the EmpSearchPG to test the page

Flow Diagram
The Final Output:

You might also like