Here is a simple search page where user can perform search operation on the basis of employee number and employee name on employee table.
We are creating a employee search page, so specify the details of page as below:
3) Create a new view object (VO):
Right click --> New View Object (This will open a wizard having 7 steps).
Step 1
Package: xxcus.oracle.apps.fnd.emprec.server
Name: XxEmployeeSearchVO
Choose the radio button 'Read-only Access' (as we are not performing any DML operation). Click Next.
Step 2
Enter the below query in 'Query Statement':
SELECT empno, ename, job, mgr, hiredate, sal, deptno FROM employee
Keep defaults for step3, 4, 5, 6
Step 7
Select check boxes for 'Generate Java File' for both 'View Object Class' and 'View Row Class'. Click Finish.
4) Create a new Application Module (AM):
Step 1
Package: xxcus.oracle.apps.fnd.emprec.server
Name: XxEmployeeAM. Click Next.
Step 2
Here we will add an instance of the VO created in (3). Select XxEmployeeSearchVO from 'Available View Objects' and shuttle it to 'Data Model' using > button.
Keep defaults for all other steps (3, 4). Click Finish.
5) Create a new Controller class :
Step 1
Select XxEmployeeSearchPG in navigator tab. Declarative form of page will be visible in structure tab.
Step 2
Right click on pageLayout region --> set new controller (This will open a popup window). Enter the below details:
package Name: xxcus.oracle.apps.fnd.emprec.webui
Class Name: XxEmployeeSearchCO
Creating the Page Layout & Setting its Properties
==========================
Page will appear as below:
messageTextInput (for emp number):
ID: empNum
Prompt: Employee Number
messageTextInput (for emp name):
ID: EmpName
Prompt: Employee Name
spacer: ID: spcr, Height: 20
4) Again create a region under pageLayout. However this time, choose 'Region Using Wizard'.
Step 1
select 'XxEmployeeAM' from Application Module drop down and select 'XxEmployeeSearchVO1' in available view usages. Click Next.
Step 2
choose region style as 'table' from drop down. Click Next.
Step 3
shuttle all the fields from available to selected attributes. Click Next.
Step 4
Change the style to messageStyledText for each row. Also modify the prompt to make it more user friendly (like empName to Employee Name).
The declarative page structure in jDev will be similar to as shown below:
Code for Performing the Search Operation
==========================
Write the below code in PFR method of controller:
1) Create a new OA workspace (xxcus) and a new project under this (xxcus).
2) Create a new OA page:
Right click on project (xxcus) --> New --> Web Tier --> OA Components --> select 'Page' item. Click OK. (This will open a popup window)We are creating a employee search page, so specify the details of page as below:
Name: XxEmployeeSearchPG
Package: xxcus.oracle.apps.fnd.emprec.webui
Right click --> New View Object (This will open a wizard having 7 steps).
Step 1
Package: xxcus.oracle.apps.fnd.emprec.server
Name: XxEmployeeSearchVO
Choose the radio button 'Read-only Access' (as we are not performing any DML operation). Click Next.
Step 2
Enter the below query in 'Query Statement':
SELECT empno, ename, job, mgr, hiredate, sal, deptno FROM employee
Keep defaults for step3, 4, 5, 6
Step 7
Select check boxes for 'Generate Java File' for both 'View Object Class' and 'View Row Class'. Click Finish.
4) Create a new Application Module (AM):
Step 1
Package: xxcus.oracle.apps.fnd.emprec.server
Name: XxEmployeeAM. Click Next.
Step 2
Here we will add an instance of the VO created in (3). Select XxEmployeeSearchVO from 'Available View Objects' and shuttle it to 'Data Model' using > button.
Keep defaults for all other steps (3, 4). Click Finish.
5) Create a new Controller class :
Step 1
Select XxEmployeeSearchPG in navigator tab. Declarative form of page will be visible in structure tab.
Step 2
Right click on pageLayout region --> set new controller (This will open a popup window). Enter the below details:
package Name: xxcus.oracle.apps.fnd.emprec.webui
Class Name: XxEmployeeSearchCO
Creating the Page Layout & Setting its Properties
==========================
Page will appear as below:
1) Create a new region under pageLayout of type defaultSingleColumn.
2) Create 3 items under defaultSingleColumn region (messageTextInput, messageTextInput, submitButton).
3) Create another item under pageLayout of type 'spacer'.
Now change the properties for each field from property inspector as shown below:
pageLayout:
ID: pageLayoutRN
AM Definition: xxcus.oracle.apps.fnd.emprec.server.XxEmployeeAM
Window Title: Employee Search Page
Title: Employee Search
defaultSingleColumn: ID: singleColRN
messageTextInput (for emp number):
ID: empNum
Prompt: Employee Number
messageTextInput (for emp name):
ID: EmpName
Prompt: Employee Name
submitButton: ID: goBtn, Prompt: Go
spacer: ID: spcr, Height: 20
4) Again create a region under pageLayout. However this time, choose 'Region Using Wizard'.
Step 1
select 'XxEmployeeAM' from Application Module drop down and select 'XxEmployeeSearchVO1' in available view usages. Click Next.
Step 2
choose region style as 'table' from drop down. Click Next.
Step 3
shuttle all the fields from available to selected attributes. Click Next.
Step 4
Change the style to messageStyledText for each row. Also modify the prompt to make it more user friendly (like empName to Employee Name).
The declarative page structure in jDev will be similar to as shown below:
==========================
- User will enter search criteria (emp num or name) and click on 'Go' button.
- We catch this button press in PFR method of controller.
- Get the criteria fields and pass those to AM where we define a method to perform search.
Write the below code in PFR method of controller:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) { super.processFormRequest(pageContext, webBean); OAApplicationModule am = pageContext.getRootApplicationModule(); if (pageContext.getParameter("goBtn") != null) { if ((!("".equals(pageContext.getParameter("empNum").trim()))) || (!("".equals(pageContext.getParameter("EmpName").trim())))) { String empNum = pageContext.getParameter("empNum"); String empName = pageContext.getParameter("EmpName"); if (("".equals(pageContext.getParameter("empNum").trim()))) { empNum = null; } Serializable[] param = { empNum, empName }; am.invokeMethod("searchEmployee", param); } else { throw new OAException("Please Enter Search Criteria.", OAException.ERROR); } } }
Below is code for searchEmployee method in XxEmployeeAMImpl.java :
public void searchEmployee(String empNum, String empName) { try { XxEmployeeSearchVOImpl vo = getXxEmployeeSearchVO1(); vo.setMaxFetchSize(-1); vo.setWhereClause(null); vo.setWhereClauseParams(null); vo.setWhereClause("EMPNO = nvl(" + empNum + ",EMPNO)" + "AND UPPER(ENAME) like UPPER('%" + empName + "%')"); System.out.println("search query - " + vo.getQuery()); vo.executeQuery(); } catch(Exception e) { e.printStackTrace(); } }
Good exercise for handson, please post more of such, thanks
ReplyDelete