Wednesday, June 15, 2016

Creating and Updating on one click in OA Framework

We will try to implement Search Page with one text item as ID. Based on ID control will go to second page. Second page contain three text rows. ID will be displayed on second page as Styled Text in all three rows
If match will be found based on ID then search result will come. If not found then empty rows will come. Based on that new data can be inserted there and existing data can be updated directly with one button click ‘Apply’ 

1. Create a New Workspace and Project
Right click Workspaces and click create new OAworkspace.
File Name – PrajkumarSearch
Project Name -- SearchDemo
package -- search.oracle.apps.PO.searchdemo

2. Create a New Application Module (AM)
Right Click on SearchDemo > New > ADF Business Components > Application Module
Name -- SearchAM
Package -- search.oracle.apps.PO.searchdemo.server

3. Enable Passivation for the Root UI Application Module (AM)
Right Click on SearchAM > Edit SearchAM > Custom Properties >
Name – RETENTION_LEVEL
Value – MANAGE_STATE
Click add > Apply > OK

4. Using Emp Table
Select * From Emp;

5. Create a New Entity Object (EO)
Right click on SearchDemo > New > ADF Business Components > Entity Object
Name – SearchEO
Package -- search.oracle.apps.PO.searchdemo.schema.server
Database Objects -- xx_create_upd_demo

Note – By default ROWID will be the primary key if we will not make any column to be primary key.
Check the Accessors, Create Method, Validation Method and Remove Method

6. Create a New View Object (VO)
Right click on SearchDemo > New > ADF Business Components > View Object
Name -- SearchVO
Package -- search.oracle.apps.PO.searchdemo.server
In Step2 in Entity Page select SearchEO and shuttle them to selected list
In Step3 in Attributes Window select columns empno, ename, job,mgr,hiredate,sal,comm,deptno and shuttle them to selected list
In Java page select Generate Java File for View Object Class: SearchVOImpl and Generate Java File for View Row Class: SearchVORowImpl

7. Add Your View Object to Root UI Application Module
Select Right click on SearchAM > Application Modules > Data Model >
Select SearchVO and shuttle to Data Model list

8. Create a New Page
Right click on SearchDemo > New > Web Tier > OA Components > Page
Name -- SearchPG
Package -- search.oracle.apps.PO.searchdemo.webui

9. Select the SearchPG and go to the strcuture pane where a default region has been created

10. Select region1 and set the following properties:
ID – PageLayoutRN
Scope -- Public
Region Style -- PageLayout
AM Definition -- search.oracle.apps.PO.searchdemo.server.SearchAM
Window Title –Page Window
Title – Page Header
Auto Footer – True

11. Create the Second Region (Main Content Region)
ID – MainRN
Region Style -- messageComponentLayout
Auto Footer – True

12. Create the first Item (Empty Field)
MainRN > New > messageTextInput
Set Following properties for new item
ID – MyId
Style Property – messageTextInput
Prompt – Id
Data Type – Number
Length – 20
Maximum Length – 100

13. Create a container Region for Go-Button
MainRN > messageLayout
Set ID -- ButtonLayout

14. Create a Item (Go Button)
Select ButtonLayout > New > Item
ID – Go
Item Style – submitButton
Attribute -- /oracle/apps/fnd/attributesets/Buttons/Go

15. Create a New Second Page
Right click on SearchDemo > New > Web Tier > OA Components > Page
Name -- CreateUpdPG
Package -- search.oracle.apps.PO.searchdemo.webui

16. Select the CreateUpdPG and go to the strcuture pane where a default region has been created

17. Select region1 and set the following properties:
ID – PageLayoutRN
Scope -- Public
Region Style -- PageLayout
AM Definition -- search.oracle.apps.PO.searchdemo.server.SearchAM
Window Title –Page Window
Title – Page Header
Auto Footer – True

18. Create the Second Region (Main Content Region)
ID – MainRN
Region Style -- table
Auto Footer – True
Records Displayed – 3

19. Create the first Item (Empty Field)
MainRN > New > item
Set Following properties for new item
ID – empno
Style Property – messageTextInput
Prompt – empno
Data Type – number
Length – 20
Maximum Length – 4
View Instance -- SearchVO1
View Attribute -- empno

Create Second Item
MainRN > New > item
Set Following properties for new item
ID – ename
Style Property – messageTextInput
Prompt – ename
Data Type – VARCHAR2
Length – 20
Maximum Length – 10
View Instance -- SearchVO1
View Attribute -- ename

Create Third Item
MainRN > New > item
Set Following properties for new item
ID – job
Style Property – messageTextInput
Prompt – job
Data Type – VARCHAR2
Length – 20
Maximum Length – 9
View Instance -- SearchVO1
View Attribute -- job

Create Fourth Item
MainRN > New > item
Set Following properties for new item
ID – mgr
Style Property – messageTextInput
Prompt – mgr
Data Type – NUMBER
Length – 20
Maximum Length – 4
View Instance -- SearchVO1
View Attribute -- mgr


Create Fifth Item
MainRN > New > item
Set Following properties for new item
ID – hiredate
Style Property – messageTextInput
Prompt – mgr
Data Type – date
Length – 20

View Instance -- SearchVO1
View Attribute -- hiredate


Create Sixth Item
MainRN > New > item
Set Following properties for new item
ID – sal
Style Property – messageTextInput
Prompt – sal
Data Type – number
Length – 20
Maximum Length – 7
View Instance -- SearchVO1
View Attribute -- sal

Create Seventh Item
MainRN > New > item
Set Following properties for new item
ID – comm
Style Property – messageTextInput
Prompt – comm
Data Type – NUMBER
Length – 20
Maximum Length – 7
View Instance -- SearchVO1
View Attribute -- comm

Create Eith Item
MainRN > New > item
Set Following properties for new item
ID – Deptno
Style Property – messagestyledText
Prompt – deptno
Data Type – NUMBER
Length – 20
Maximum Length – 2
View Instance -- SearchVO1
View Attribute -- deptno


20. Add Controller for Page SearchPG Select PageLayoutRN right click Set New Controller
Package Name -- prajkumar.oracle.apps.fnd.searchdemo.webui
Class Name -- SearchCO
Add Following code in that controller

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
      
    if(pageContext.getParameter("Go")!=null)
    {
      String userContent=pageContext.getParameter("MyId");
      HashMap hmap=new HashMap();
      hmap.put("MyId",userContent);
      
      pageContext.setForwardURL(
            "OA.jsp?page=/search/oracle/apps/PO/searchdemoPRJ/webui/CreateUpdPG",
            null,                             
            OAWebBeanConstants.KEEP_MENU_CONTEXT,                                                    
            null,                                                    
            hmap,                             
            true, 
            OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
            OAWebBeanConstants.IGNORE_MESSAGES);  
    }
    
    
  }

}

21. Add Return Link to come back to SearchPG from CreateUpdPG
Select CreateUpdPG in Structure Panel Select PageLayoutRN > New > returnNavigation
ID – ReturnLink
Destination URI – OA.jsp?page=/search/oracle/apps/PO/searchdemo/webui/SearchPG&retainAM=Y
Text – Return to SearchPG
 
22. Add pageButtonBar region to implement Apply Button
Right click on PageLayout > New > Region
Set following properties for new region
ID -- ButtonBar
Region Style – pageButtonBar
Select ButtonBar right click > New > Item
Select newly created item and set following properties –
ID – Apply
Item Style – submitButton
Attribute Set -- /oracle/apps/fnd/attributesets/Buttons/Apply
 
23. Add Controller for Page CreateUpdPG Select PageLayoutRN right click Set New Controller
Package Name -- search.oracle.apps.PO.searchdemo.webui
Class Name -- CreateUpdCO
Add Following code in that controller
 

import java.io.Serializable;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;

  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
    OAApplicationModule am=pageContext.getApplicationModule(webBean);
    
    String val=pageContext.getParameter("MyId");
    Serializable[] params = {val};
    am.invokeMethod("createRow",params);
    
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am=pageContext.getApplicationModule(webBean);
    
    if(pageContext.getParameter("Apply")!=null)
    {
      am.getOADBTransaction().commit();
      
      pageContext.setForwardURL(
                "OA.jsp?page=/search/oracle/apps/PO/searchdemoPRJ/webui/searchPG",
                null,         
                OAWebBeanConstants.KEEP_MENU_CONTEXT,         
                null,         
                null,         
                true,         
                OAWebBeanConstants.ADD_BREAD_CRUMB_NO,         
                OAWebBeanConstants.IGNORE_MESSAGES);    
    }
  }

}
24. Add Following code in SearchAMImpl.java

import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.jbo.Row;

  public void createRow(String Val)
  {
    EmpVOImpl vo=getEmpVO1();
    vo.initQuery(Val);
    
    int rowCount=vo.getRowCount();
    if(rowCount<7)
    {
      for(int i=7;i!=rowCount;rowCount++)
      {
        Row studrow = vo.createRow(); 
                  vo.last();
                  vo.next();
                        
                  vo.insertRow(studrow);
                  vo.setCurrentRow(studrow);
                  vo.getCurrentRow().setAttribute("Deptno",Val);
                  studrow.setNewRowState(Row.STATUS_INITIALIZED);
      }
    }

25. Add Following code in SearchVOImpl.java

import oracle.jbo.domain.Number;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OAViewObjectImpl;

  public void initQuery(String Val)
  {
  if((Val!=null)&&(!("".equals(Val.trim()))))
  {
    Number Val2=null;
    
    try
    {
      Val2=new Number(Val);
          }
          catch(Exception e)
          {
            throw new OAException("AK", "FWK_TBX_INVALID_EMP_NUMBER");
          }
          setWhereClause("Deptno=:1");
    setWhereClauseParams(null); 
         setWhereClauseParam(0, Val2);
         executeQuery();
  }
  }

26. Congratulation you have successfully finished. Run Your SearcgPG page and Test Your Work

a
b
c
Back to Search Page from CreateUPtPG

No comments:

Post a Comment