Saturday 20 July 2013

CREATING UPDATE PAGE

Here are the steps for creating 'Employee create update' page. I have modified thesearch page created in previous post.

1) Create a new Entity Object (EO):
===================

Right click on 'emprec' package and create a new entity object (This will open a wizard having 5 steps).

Step 1
        Package: xxcus.oracle.apps.fnd.emprec.schema.server
        Name: XxEmployeeEO
        Schema Object (in Database Object): EMPLOYEE
        Click Next.

Step 2
        Keeps default (all attributes selected). Click Next.

Step 3
        If there is any primary key in DB table, then keep all defaults else select a primary key (like empno). Click Next.

Step 4
       Keep defaults and click on Next.

Step 5
       Keep 'Generate Default View Object' uncheked and click on Finish.

2) Create a new View Object (VO) based on EO created in (1):
====================
Right click --> New View Object (This will open a wizard having 7 steps).

Step 1
        Package: xxcus.oracle.apps.fnd.emprec.server
        Name: XxEmployeeVO
       Choose the radio button 'Updatable access through Entity Objects'. Click Next.

Step 2
     Select the xxcus.oracle.apps.fnd.emprec.schema.server.XxEmployeeEO from 'Available' list and shuttle it to 'Selected' list. Click Next.

Step 3
     Move all the columns except WHO columns (lastUpdateLogin, createdBy...) to 'Selected' list from 'Available' list attributes.
Click Next.

      Keep defaults for step 4, 5 & 6.

Step 7
      Select check boxes for 'Generate Java File' for both 'View Object Class' and 'View Row Class'. Click Finish.

Double Click on XxEmployeeAM and shuttle XxEmployeeVO from 'Available view objects' to 'Data Model'.
(now there are two VO instances in AM :XxEmployeeSearchVO1 & XxEmployeeVO1).

3) Edit Employee Search Page (XxEmployeeSearchPG):
====================
(This includes adding a 'create button' at top & 'update' icon on every row in search result. Modified page will appear as below:).




















Step 1
Right click on pageLayoutRN and add a new region. Set properties as below:
        Region Style: pageButtonBar
        ID: pageBtnBarRN
        
        Right click on pageBtnBarRN region and add a new item:
              Item Style: submitButton
              ID: createBtn
              Prompt: Create Employee

Step 2
Right click on XxEmployeeSearchVO1 table region and add an item. Set the below properties:
              Item Style: Image
              ID: updateImg
              Prompt: Update
              Image URI: updateicon_enabled.gif
              Action Type: fireAction
              Event: updateEvent
              Parameters: it will open a new window. Add a parameter as below:
                 Name: p_empNum value: ${oa.XxEmployeeSearchVO1.Empno}

4) Create a new Update Create page:
====================
(Here user can either create a new employee or can update existing one. The page will appear as shown below: ).



















Right click emprec --> New --> Web Tier --> OA Components --> select 'Page' item. Click OK. (This will open a popup window)
We are creating Employee Create Update Page, so specify the details of page as below:
          Name: XxEmployeeCreateUpdatePG
          Package: xxcus.oracle.apps.fnd.emprec.webui

Create a new region under pageLayout of type 'header'

Create another region under the header region using wizard
(This will open a wizard window having 4 steps):

  • Select 'XxEmployeeAM' from Application Module drop down and select 'XxEmployeeVO1' in available view usages. Click Next.
  • Choose region style as 'defaultSingleColumn' from drop down. Click Next.
  • Shuttle all the fields from available to selected attributes. Click Next.
  • Change the style to messageStyledText for Empno and messageTextInput for other remaining rows. Also modify the prompt to make it more user friendly (like empName to Employee Name).
  • Click Next and finish.

Right click on pageLayoutRN and add a new region

Set properties as below:
        Region Style: pageButtonBar
ID: pageBtnBarRN

Right click on pageBtnBarRN region and add 2 new items of type submitButton:
Item Style: submitButton
ID: saveBtn;  ID: cancelBtn
prompt: Save; prompt: Cancel

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 Create Update Page
                 Title: Employee Create Update

header:      ID: empCreateRN

5) Create a new controller for Update Create page:
====================
Step 1
Select XxEmployeeCreateUpdatePG 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: XxEmployeeCreateUpdateCO
   
The declarative page structure in jDev will be similar to as shown below:



6) Code for Performing Create & Update Operation
====================

  • Catch the 'create button' or 'Update' event in PFR method of XxEmployeeSearchCO (controller of XxEmployeeSearchPG page) and navigate to 'Employee Create Update Page' (XxEmployeeCreateUpdatePG). We also pass a token (in the form of HashMap) to indicate whether it is a create or update operation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// XxEmployeeSearchCO :: PFR
if (pageContext.getParameter("createBtn") != null) {
    HashMap hm = new HashMap(); //com.sun.java.util.collections.HashMap;
    hm.put("event", "create");
pageContext.forwardImmediately("OA.jsp?page=/xxcus/oracle/apps/
fnd/emprec/webui/XxEmployeeCreateUpdatePG",
null, (byte)0, null, hm, false, null);
}
 
if ("updateEvent".equals(pageContext.getParameter(EVENT_PARAM))) {
    String p_empNum = pageContext.getParameter("p_empNum");
    HashMap hm = new HashMap();
    hm.put("event", "update");
    hm.put("empNum", p_empNum);
pageContext.forwardImmediately("OA.jsp?page=/xxcus/oracle/apps/
fnd/emprec/webui/XxEmployeeCreateUpdatePG",
null, (byte)0, null, hm, false, null);
}
  • Once navigated to create page, we have to initialize the XxEmployeeVO1, so data entered by user in the fields can be mapped to its attributes. And in case of 'update', populate the records for the employee. We write this code in PR method of XxEmployeeCreateUpdateCO (controller of XxEmployeeCreateUpdatePG page). First we check if it is create or update event and will call a method from AM accordingly:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// XxEmployeeCreateUpdateCO :: PR method
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
    super.processRequest(pageContext, webBean);
    am = pageContext.getRootApplicationModule();
 
    if ("create".equals(pageContext.getParameter("event"))) {
        am.invokeMethod("initCreateEmp");
    }
 
    if ("update".equals(pageContext.getParameter("event"))) {
        String empNum = pageContext.getParameter("empNum");
        Serializable[] param = { empNum };
        am.invokeMethod("initUpdateEmp", param);
    }
}

Write below methods in XxEmployeeAMImpl.java file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// XxEmployeeAMImpl ::
public void initCreateEmp() {
    try {
  XxEmployeeVOImpl empCreateVO = getXxEmployeeVO1();
  empCreateVO.setMaxFetchSize(0);
  XxEmployeeVORowImpl row = (XxEmployeeVORowImpl)empCreateVO.createRow();
 
// here we are setting the employee number using a DB Sequence
  Number empNum = getOADBTransaction().getSequenceValue("EMPLOYEE_NUMBER_S");
  row.setEmpno(empNum);
  empCreateVO.insertRow(row);
  row.setNewRowState(Row.STATUS_INITIALIZED);
 } catch () {
  e.printStackTrace();
  }
}
 
public void initUpdateEmp(String empNum) {
    try {
  XxEmployeeVOImpl employeeVO = getXxEmployeeVO1();
  employeeVO.setWhereClause(null);
  employeeVO.setWhereClauseParams(null);
  employeeVO.setWhereClause("EMPNO = :1");
  employeeVO.setWhereClauseParam(0, empNum);
  employeeVO.setMaxFetchSize(-1);
  employeeVO.executeQuery();
  } catch (Exception e) {
   e.printStackTrace();
   }
}

Finally, user can click on 'Save' button to commit the data or 'Cancel' to return back to search page.
  • We will catch the 'save' or 'cancel' button click in PFR method of XxEmployeeCreateUpdateCO and call a method from AM accordingly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// XxEmployeeCreateUpdateCO :: PFR method
public void processFormRequest(OAPageContext pageContext,
                               OAWebBean webBean) {
    super.processFormRequest(pageContext, webBean);
 
    OAApplicationModule am = pageContext.getRootApplicationModule();
 
    if (pageContext.getParameter("cancelBtn") != null) {
   pageContext.forwardImmediately("OA.jsp?page=/xxcus/oracle/apps
   /fnd/emprec/webui/XxEmployeeSearchPG", null, (byte)0, null, null, false, null);
    }
 
    if (pageContext.getParameter("saveBtn") != null) {
     
 /*Here we are performing commit operation
   and returning back to search page.
   Also we are fetching the updated/created
   emp num so we can display a message on search page*/
    
  String savedEmp = am.invokeMethod("commit").toString();
        HashMap hm = new HashMap();           
        hm.put("updated", "Y");
        hm.put("empUpdated", savedEmp);
   pageContext.forwardImmediately("OA.jsp?page=/xxcus/oracle/apps
   /fnd/emprec/webui/XxEmployeeSearchPG", null, (byte)0, null, hm, false, null);
    }
}

Below is 'commit' method created in AMImpl class:

1
2
3
4
5
6
7
8
9
10
11
public String commit() {
    try {
  XxEmployeeVOImpl employeeVO = getXxEmployeeVO1();
  XxEmployeeVORowImpl row = (XxEmployeeVORowImpl)employeeVO.first();
  String savedEmp = row.getEmpno().toString();
  getOADBTransaction().commit();
  return savedEmp;
  } catch (Exception e) {
   e.printStackTrace();
   }
}
Below is code to display successful message on search page:
1
2
3
4
5
6
7
8
9
10
11
12
// XxEmployeeSearchCO :: PR method
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
    super.processRequest(pageContext, webBean);
 
    if ("Y".equals(pageContext.getParameter("updated"))) {
        String updatedEmp = pageContext.getParameter("empUpdated");
        throw new OAException("Employee Number " + updatedEmp +
                              " has been saved successfully.",
                              OAException.CONFIRMATION);
    }
 
}


Message will be displayed after saving the data as shown below:



















No comments:

Post a Comment