Adding button and calling Create page from search
Step1: Right click on “ResultsTable” under QueryRN which created in previous exercise of Search page and select New > tableActions
It Automatically creates a flowLayout region and change region ID to ButtonLayout
Right click on ButtonLayout and select New > Item and set properties as below
ID=Create
Item Style = submitButton
Prompt=Create
Step2: Create controller for ResultsTable region
Right click on ResultsTable region in EmpSearchPG and select “Set New Controller”
Specify package name = trng2.oracle.apps.ak.emp.webui
Name=EmpResultsCO
Step3: In the process form request method of EmpResultsCO writhe below statement to call EmpCreatePG
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{ super.processFormRequest(pageContext, webBean);
if (pageContext.getParameter(“Create”) != null)
{ // Navigate to the “Create Employee” page while retaining the AM.
pageContext.setForwardURL(“OA.jsp?page=/trng2/oracle/apps/ak/emp/webui/EmpCreatePG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // Retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
OAWebBeanConstants.IGNORE_MESSAGES);
}
}
Syntax: setForwardURL
void setForwardURL(String url,
String functionName,
byte menuContextAction,
String menuName,
com.sun.java.util.collections.HashMap parameters,
boolean retainAM,
String addBreadCrumb,
byte messagingLevel)
Parameters:
url – The URL to forward to. Example: OA.jsp?page=/oracle/apps/po/webui/myPage
functionName – The function to select with the current menu context
menuContextAction – Determines the behavior of the MenuContext after forwarding to the new page. Some of the values are OAWebBeanConstants.KEEP_MENU_CONTEXT(keeps the menu context as is), OAWebBeanConstants.KEEP_NO_DISPLAY_MENU_CONTEXT (keeps the menu context as is, but will not display all menus including global buttons) etc
menuName – The name of the HOMEPAGE menu to reset the Menu context. If the menuName is not of type HOMEPAGE a OAException will be thrown. You can pass null otherwise
parameters – HashMap of parameter name/value pairs to append to the forward url
retainAM – If true, all the cached application modules will be retained. If false, all the cached application modules will be released
addBreadCrumb – Controls breadcrumbs behavior. Some of the values are OAWebBeanConstants.ADD_BREAD_CRUMB_YES, OAWebBeanConstants.ADD_BREAD_CRUMB_NO etc.
messagingLevel – Used to determine if the forward should be cancelled if messages or exceptions of level Error, Warning, Information or Confirmation are found. Possible values are OAWebBeanConstants.IGNORE_MESSAGES, OAException.ERROR etc
Changing code in Apply button of EmpCreatePG so that it should direct back to EmpSearchPG on clicking button
In EmpCreateCO processformrequest method change code as below (highlighted lines are those which are newly added in this step)
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
EmpAMImpl am = (EmpAMImpl)pageContext.getApplicationModule(webBean);
if (pageContext.getParameter(“Apply”)!=null) {
am.apply();
OAException cmsg = new OAException(“Employee created”,OAException.CONFIRMATION);
pageContext.putDialogMessage(cmsg);
pageContext.forwardImmediately(“OA.jsp?page=/trng2/oracle/apps/ak/emp/webui/EmpSearchPG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true,
OAWebBeanConstants.ADD_BREAD_CRUMB_YES);
}
if (pageContext.getParameter(“Cancel”)!=null) {
am.cancel();
OAException cmsg = new OAException(“Employee Not created”,OAException.CONFIRMATION);
pageContext.putDialogMessage(cmsg);
pageContext.forwardImmediately(“OA.jsp?page=/trng2/oracle/apps/ak/emp/webui/EmpSearchPG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true,
OAWebBeanConstants.ADD_BREAD_CRUMB_YES);
}
}
Note: Difference of forwardImmediately and setForwardURL: Set forward url forwards to the page only after event got completed where as forward immediately move immediately leaving remaining commands in that event.
Implementing Delete and Update buttons in search page (Switcher)
Note: Please check that you have remove method in your EO to implement delete functionality through EO
Scenario: For simplicity, assume that if there is end date value exist in FWK_TBX_EMPLOYEES table means employee inactive irrespective of date value in it
Creating Delete and Update switchers
Step1: Creating both switchers for delete and update. In order to do that need to modify query in EmpSummaryVO
Open EmpSummaryVO by right clicking it and selecting Edit EmpSummaryVO. Select Sql Statement and change the query as below
SELECT EmployeeEO.EMPLOYEE_ID,
EmployeeEO.FULL_NAME AS EMPLOYEE_NAME, EmployeeEO.EMAIL_ADDRESS AS EMPLOYEE_EMAIL, EmployeeEO1.EMPLOYEE_ID AS MANAGER_ID, EmployeeEO1.FULL_NAME AS MANAGER_NAME, EmployeeEO1.EMAIL_ADDRESS AS MANAGER_EMAIL, flkp.meaning AS POSITION_DISPLAY,
DECODE(nvl(to_char(EmployeeEO.END_DATE), ‘N’),
‘N’, ‘DeleteEnabled’, ‘DeleteDisabled’) AS DELETE_SWITCHER,
DECODE(nvl(to_char(EmployeeEO.END_DATE), ‘N’),
‘N’, ‘DeleteEnabled’, ‘DeleteDisabled’) AS UPDATE_SWITCHER
FROM FWK_TBX_EMPLOYEES EmployeeEO,
FWK_TBX_EMPLOYEES EmployeeEO1,
FWK_TBX_LOOKUP_CODES_VL flkp
WHERE EmployeeEO.MANAGER_ID = EmployeeEO1.EMPLOYEE_ID (+)
and EmployeeEO.POSITION_CODE = flkp.lookup_code
and flkp.lookup_type = ‘FWK_TBX_POSITIONS’
Step2: Right click on ResultsTable in the structure panel and select New Switcher and set properties as below
ID=DeleteSwitcher
Region Style = switcher
View Instance=EmpSummaryVO1
View Attribute=DeleteSwitcher
Prompt=Delete
Step3: Switcher region will be having one default case. Case is used to define various options of that attribute value. You need to create that many cases that data base column returns. Here DELETE_SWITCHER in query returns either DeleteDisabled or DeleteEnabled. So you need to create two cases
Right click on <case> under DeleteSwitcher and select New Item and set properties as below
ID=DeleteDisabled (Note: this value should match to one of the value that return by column DELETE_SWITCHER you defined with decode in VO Sql query)
Item Style = Image
Image URI = deleteicon_disabled.gif
Step4: Right click on DeleteSwitcher and select NewCase to create 2nd for enabled
Right click on <case> under DeleteSwitcher and select New Item and set properties as below for second case
ID=DeleteEnabled (Note: this value should match to one of the value that return by column DELETE_SWITCHER you defined with decode in VO Sql query)
Item Style = Image
Image URI = deleteicon_enabled.gif
Action Type=fireAction
Event=delete
Parameters: Click on Parameters which opens below dialog box
Click on “Add Parameters” and set Name DelEmpId and value ${oa.EmpSummaryVO1.EmployeeId}
(Note: above syntax is called SPELL)
Step5: Right click on ResultsTable in the structure panel and select New Switcher and set properties as below
ID=UpdateSwitcher
Region Style = switcher
View Instance=EmpSummaryVO1
View Attribute=UpdateSwitcher
Prompt=Update
Step6: Switcher region will be having one default case. Case is used to define various options of that attribute value. You need to create that many cases that data base column returns. Here UPDATE_SWITCHER in query returns either UpdateDisabled or UpdateEnabled. So you need to create two cases
Right click on <case> under UpdateSwitcher and select New Item and set properties as below
ID=UpdateDisabled (Note: this value should match to one of the value that return by column UPDATE_SWITCHER you defined with decode in VO Sql query)
Item Style = Image
Image URI = updateicon_disabled.gif
Step7: Right click on UpdateSwitcher and select NewCase to create 2nd for enabled
Right click on <case> under UpdateSwitcher and select New Item and set properties as below for second case
ID=UpdateEnabled (Note: this value should match to one of the value that return by column UPDATE_SWITCHER you defined with decode in VO Sql query)
Item Style = Image
Image URI = updateicon_enabled.gif
Action Type=fireAction
Event=update
Parameter:
Create parameter with name “UpdateEmpId” and value ${oa.EmpSummaryVO1.EmployeeId}
Step8: In EmpResultsCO add below code in processformrequest
if (“delete”.equals(pageContext.getParameter(EVENT_PARAM))) {
String DelEmpId = pageContext.getParameter(“DelEmpId”);
Serializable[] params = { DelEmpId };
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod(“deleteEmp”,params);
OAException msg = new OAException(“Employee Deleted”,OAException.CONFIRMATION);
pageContext.putDialogMessage(msg);
pageContext.forwardImmediatelyToCurrentPage(null,true,OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
Step9: In EmpAMImpl write below method
public void deleteEmp(String DelEmpId) {
if ( (DelEmpId!=null) || (“”.equals(DelEmpId)))
{
EmpVOImpl vo;
vo = getEmpVO1();
vo.setWhereClause(null);
vo.setWhereClause(“EMPLOYEE_ID=’”+DelEmpId+”‘”);
vo.executeQuery();
vo.first().remove();
apply(); //note this apply method we have written in earlier session. Otherwise use getTransaction().commit();
}
}
Code to Update switcher
Step1: In EmpResultsCO.java write below code in process form request. “update” is the event created for UpdateSwitcher UpdateEnabled case created in previous session. UpdateEmpId is the parameter created for same case item and this parameter we are passing to EmpCreatePG.
if (pageContext.getParameter(EVENT_PARAM).equals(“update”)){
String updEmpId = pageContext.getParameter(“UpdateEmpId”);
HashMap hm = new HashMap();
hm.put(“UpdateEmpId”,updEmpId);
pageContext.setForwardURL
(“OA.jsp?page=/trng2/oracle/apps/ak/emp/webui/EmpCreatePG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
hm, //null, params
true, //retain am
OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
OAWebBeanConstants.IGNORE_MESSAGES
);
}
Step2: In EmpCreateCO.java change logic as below in processRequest method. Because we need to identify whether this page is called when selected “Create” or “Update” in EmpSearchPG and accordingly it should initiate the row
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAMessageRadioButtonBean uMr = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMr”);
uMr.setName(“Title”);
uMr.setValue(“Mr”);
OAMessageRadioButtonBean uMiss = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMiss”);
uMiss.setName(“Title”);
uMiss.setValue(“Miss”);
OAMessageRadioButtonBean uMrs = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMrs”);
uMrs.setName(“Title”);
uMrs.setValue(“Mrs”);
EmpAMImpl am = (EmpAMImpl)pageContext.getApplicationModule(webBean);
if (!((pageContext.getParameter(“UpdateEmpId”)==null) || (pageContext.getParameter(“UpdateEmpId”).equals(“”)))) {
String pEmpId = pageContext.getParameter(“UpdateEmpId”);
am.updateEmp(pEmpId);
}
else
{
am.createEmployee();
}
}
Step3: In EmpAMImpl.java write below procedure which is calling from above step
public void updateEmp(String empnum) {
EmpVOImpl vo = getEmpVO1();
vo.setWhereClause(null);
vo.setWhereClause(“EMPLOYEE_ID = “+empnum);
vo.executeQuery();
vo.first();
}
Step4: Also as we are using setwhercclause for VO in delete and update methods, we need to remove it at the time new record creation. Hence please make below change in createEmployee method in EmpAMImpl.java
public void createEmployee() {
EmpVOImpl empVo = getEmpVO1();
// if (!empVo.isPreparedForExecution())
empVo.setWhereClause(null);
empVo.executeQuery();
Row row = empVo.createRow();
empVo.insertRow(row);
}