oaf table region dml operations

38
OAF Table Region DML Operations January 1, 2015 · by altunkan · in Oracle Application Framework (OAF) Hello, In this tutorial, OAF Table Region DML operations will be implemented. We will cover the following topics: Fetching rows from database table and display them on table region Adding single rows into table region Removing multiple rows from table region. Oracle WHO Columns In Oracle E-Business Suite Database, most tables have file who columns. We are also using these columns in our custom applications. These columns are: CREATED_BY: The NUMBER column that shows which FND_USER-USER_ID created the row CREATION_DATE: The DATE column that shows when row is created. LAST_UPDATE_DATE: The DATE column that shows when row is updated. LAST_UPDATED_BY: The NUMBER column that shows which FND_USER- USER_ID updated the row LAST_UPDATE_LOGIN: The NUMBER column that shows which USERENV (‘SESSIONID’) updated the row If WHO columns are not included in database table, correspending entitiy object must have related set methods overwritten. It would be better if who columns would be created in database tables. Before starting an OAF application, creating database model would be beneficial. In addition, make sure that primay and foreign keys are created with database tables. Foreign keys will allow JDeveloper to generate association and view link by itself. Run the following script in order to create database table. Setup Script Oracle PL/SQL 1 2 3 4 create table hr.xx_oaf_anil_personel ( person_id number, first_name varchar2(120),

Upload: nagarajuvcc123

Post on 13-Feb-2016

96 views

Category:

Documents


16 download

DESCRIPTION

OAF Table Region DML Operations

TRANSCRIPT

Page 1: OAF Table Region DML Operations

OAF Table Region DML OperationsJanuary 1, 2015 · by altunkan · in Oracle Application Framework (OAF)

Hello,In this tutorial, OAF Table Region DML operations will be implemented.We will cover the following topics:

Fetching rows from database table and display them on table region Adding single rows into table region Removing multiple rows from table region.

Oracle WHO ColumnsIn Oracle E-Business Suite Database, most tables have file who columns. We are also using these columns in our custom applications. These columns are:

CREATED_BY: The NUMBER column that shows which FND_USER-USER_ID created the row

CREATION_DATE: The DATE column that shows when row is created. LAST_UPDATE_DATE: The DATE column that shows when row is updated. LAST_UPDATED_BY: The NUMBER column that shows which FND_USER-

USER_ID updated the row LAST_UPDATE_LOGIN: The NUMBER column that shows which USERENV

(‘SESSIONID’) updated the rowIf WHO columns are not included in database table, correspending entitiy object must have related set methods overwritten. It would be better if who columns would be created in database tables.Before starting an OAF application, creating database model would be beneficial. In addition, make sure that primay and foreign keys are created with database tables. Foreign keys will allow JDeveloper to generate association and view link by itself.Run the following script in order to create database table.Setup ScriptOracle PL/SQL

1234567891011

 create table hr.xx_oaf_anil_personel (    person_id                   number,    first_name                  varchar2(120),    last_name                   varchar2(120),    salary                      number,    date_of_birth               date,    hire_date                   date,    created_by                  number,    creation_date               date,    last_update_date            date,    last_updated_by             number,    last_update_login           number

Page 2: OAF Table Region DML Operations

121314151617181920212223242526272829

); alter table hr.xx_oaf_anil_personeladd constraint xx_oaf_anil_personel_pk primary key (person_id);  create public synonym xx_oaf_anil_personel for hr.xx_oaf_anil_personel; create sequence hr.xx_oaf_anil_personel_sstart with 1increment by 1minvalue 1nocache nocycle noorder; 

1.Open JDeveloper. Right click to your project and select “New”.

2. Select “ADF Business Components from Tables” from “ADF Business Componenets” sub-menu under Business Tier and

Page 3: OAF Table Region DML Operations

click Ok button. 3. Click Next button in order to move on next step.4. In first step, Entity Object will be created. Define your package properly. Select your Schema from drop-down menu and click to “Query” button. Find your database table under “Available” section and click to the left-to-right arrow for moving it into “Selected” section. Click to the “Next” button.

5. In second step, updatable view object will be created. Select Entity Object from “Available” section and move it to selected. Change the name and package properly.

6. In third step, read-only view objects will be defined. These read-only view objects may be list of value queries. In this tutorial, we will not use and lov or poplist. Therefore just click to Next button.7. In fourth step, Application Module will be created. Select Application Module chechbox. Define your package and Name properly.

Page 4: OAF Table Region DML Operations

8. Just click to the Next button in fifth step.9. In the last step, click to the Finish button. JDeveloper will start generating BC4J objects and packages.

10. After business componenets will be created, the strcuture for packages look like following:

11. Right click to project and select New. Under Web Tier menu select OA Componenets sub-menu. Select Page object and click Ok button.

Page 5: OAF Table Region DML Operations

12. Give a proper name and package to the page.

13. Give proper ID to pageLayoutRegion. Give proper titles to “Window Title” and “Title” attributes ınde pageLayoutRegion. Set “AM Definition” by selecting your application module.

14. Run the page and check everyting is Ok.

15. Set a controller object for pageLayoutRegion by right click to PageLayoutRN and select “Set New Controller”.

16. Give proper names to class name and package name.

Page 6: OAF Table Region DML Operations

17. Create a header region under pageLayoutRegion. Right click to PageLayoutRN and select “New Region”. Set “Region Type” as “Header”. Give proper ID and text values. 18. Create an advanced table under header region.

REGION STYLE ID VIEW INSTANCE WIDTH

advancedTable  DmlAdvanceTableRN  XxOafAnilPersonelEOVO1 100%

 19. Add 5 columns under advanced table by right clicking to DmlAdvanceTableRN and select New -> Column. 20. Create 5 column headers under 5 columns. 

21. At this step, the page structure should be look like this:22. Give proper ID and prompt values to columns and column headers.column1ID: FirstNameColsortableHeader1ID: FirstNameColHdrPrompt: First Namecolumn2 ID: LastNameColsortableHeader2ID: LastNameColHdrPrompt: Last Name

Page 7: OAF Table Region DML Operations

column3ID: SalaryColsortableHeader3ID: SalaryColHdrPrompt: Salarycolumn4ID: DateOfBirthColsortableHeader4ID: DateOfBirthColHdrPrompt: Date of Birthcolumn5ID: HireDateColsortableHeader5ID: HireDateColHdrPrompt: Hire Date

23. At this step, the page structure should be look like this:   24. Create messageTextInput items under columns. FirstNameCol->New->Item

ID ITEM STYLE DATA TYPE MAXIMUM LENGTH VIEW ATTRIBUTE

FirstName messageTextInput VARCHAR2 120 FirstName

LastNameCol->New->ItemID ITEM STYLE DATA TYPE MAXIMUM LENGTH VIEW ATTRIBUTE

LastName messageTextInput VARCHAR2 120 LastName

SalaryCol->New->Item

Page 8: OAF Table Region DML Operations

ID ITEM STYLE DATA TYPE MAXIMUM LENGTH VIEW ATTRIBUTE

Salary messageTextInput NUMBER Salary

DateOfBirthCol->New->ItemID ITEM STYLE DATA TYPE MAXIMUM LENGTH VIEW ATTRIBUTE

DateOfBirth messageTextInput DATE DateOfBirth

HireDateCol->New->ItemID ITEM STYLE DATA TYPE MAXIMUM LENGTH VIEW ATTRIBUTE

HireDate messageTextInput DATE HireDate

25. At this step, the page structure should be look like this:  26.In order to display table data on page load, SQL query in View Object must be executed. Open the controller java file which is created in step 16. Controller objects have 2 methods. These are:

processRequest: This method runs before page renders. processFormRequest: This methods runs when an action is happened on the

page.In application module java file, we will write a method which will execute the sql query in view object which is attached to table region in the page. However, before writing application module method, we need to add an initQuery method into view

Page 9: OAF Table Region DML Operations

object implementation file. Open “<YourVoName>Impl.java file.

Add the following method into view object impl file.initQueryJava

12345

     public void initQuery() {        executeQuery();    } 

Open application module impl java file.

Add the following method into application module implementation java file. This method will check the vo is null or not and then call the initQuery method in view object implementation file.executeOafAnilPersonelVOJava

12345

     public void executeOafAnilPersonelVO() {        XxOafAnilPersonelEOVOImpl vo = getXxOafAnilPersonelEOVO1();        if (vo == null) {            throw new OAException("Error: XxOafAnilPersonelEOVOImpl is null");

Page 10: OAF Table Region DML Operations

6789

        }        vo.initQuery();    } 

Open controller object again and add the following code in processRequest method.processRequestJava

12345678910

   public void processRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processRequest(pageContext, webBean);    //get application module object from the context by sending webBean. webBean object represents pageLayoutRegion because controller object is attached to it.    OAApplicationModule am = pageContext.getApplicationModule(webBean);    //call application module method    am.invokeMethod("executeOafAnilPersonelVO");  } 

27. Run the page and test it. Table will be empty since no rows are added into

database table.

 Add Row1. Create tableActions into the advanced table region. Right click to DmlAdvanceTableRN and select New -> tableActions. Change flowLayout region ID to a proper name.

Page 11: OAF Table Region DML Operations

  2. Right click to TableActionsRN and select New->Item. Change Item properties with following:

ID ITEM STLE PROMPT ACTION TYPE EVENT

AddNewRow button Yeni Satır Ekle firePartialAction addNewRow

3. Double click to Entity Object and open the wizard. Move to the “Java” section and select “Create Method” checkbox. Click OK button and the wizard will be closed. This will overwirte create method in entity object java file. This method will be called whenever a row is created. Initial attribute values can be set in this method. In this tutorial, primary key of table will be set with a number value which will be fetched from a database sequence object.

Page 12: OAF Table Region DML Operations

4. Open entity object implementation java file. Change the create method with the following.createJava

12345678910111213

     /**Add attribute defaulting logic in this method.     */    public void create(AttributeList attributeList) {        super.create(attributeList);        //get transaction        OADBTransactionImpl transaction = (OADBTransactionImpl)getOADBTransaction();        //get next value from sequence in transaction        Number PersonId = transaction.getSequenceValue("HR.XX_OAF_ANIL_PERSONEL_S");        //set it to primary key        setPersonId(PersonId);    } 

5. Open application module java file and create addNewRow method.addNewRowJava

1234

     public void addNewRow() {        //Find view object from application module        OAViewObject vo = (OAViewObject)getXxOafAnilPersonelEOVO1();

Page 13: OAF Table Region DML Operations

5678910111213141516

        //unless vo query is executed or if no row has inserted before, setMaxFetchSize to 0        if (vo.getFetchedRowCount() == 0) {            vo.setMaxFetchSize(0);        }        //create a row object from view object. At this point execution will jump to entity object create method        Row row = vo.createRow();        //insert row into view object        vo.insertRow(row);        //in order to keep row state, set it as initialized.        row.setNewRowState(Row.STATUS_INITIALIZED);    } 

6. Open controller object java file and write following code in processFormRequest method.processFormRequestJava

123456789101112

   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processFormRequest(pageContext, webBean);        OAApplicationModule am = pageContext.getApplicationModule(webBean);    //catch the button action which will be created in table's tableActions section. Pay attention to ID value of button is used for catching the action.    if ("addNewRow".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {        am.invokeMethod("addNewRow");    }  } 

7. Up to this point, all these operations take action on front end. In OAF, transaction management is handled by application module. One application module represents one transaction. When a transaction is ended with commit or rollback, all of the updatable view objects (view object which is derived from entity object) pass transaction data to the entity object and prepared statements are executed by OAF in order to insert data into table and commit or rollback the transaction. In order to end transaction, we need a submit button in the page.

Page 14: OAF Table Region DML Operations

8. Right click to pageLayoutRegion and select New->Region. Change the region properties with the followings:

ID REGION STYLE

PageButtonBarRN  pageButtonBar

Right click to pageButtonBar and select New->Item. Change the Item properties with the followings:

ID ITEM STYLE PROMPT

Apply submitButton Kaydet

9. Create an apply method in application module java file. This method will get the transaction and commit it.applyJava

12345

     public void apply() {        getOADBTransaction().commit();    } 

10. Open controller object java file and change processFormRequest method with the following.processFormRequestJava

Page 15: OAF Table Region DML Operations

123456789101112131415

   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processFormRequest(pageContext, webBean);    //call application module object from pageContext with pageLayoutBean    OAApplicationModule am = pageContext.getApplicationModule(webBean);    //Catch the submit button action. Pay attention that this is different from calling actions. This will post data.    if (pageContext.getParameter("Apply") != null) {        am.invokeMethod("apply");    }    else if ("addNewRow".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {        am.invokeMethod("addNewRow");    }  } 

11. Run the page and test the results.

xx_oaf_anil_personelOracle PL/SQL

123

 select * from xx_oaf_anil_personel; 

Results:

Multiple Row Delete1. In order to mark the rows for deleting, add a transient attribute into view object. Double click to the view object and open the wizard.2. Move to the “Attributes” section and click to the “New” button.

Page 16: OAF Table Region DML Operations

3. Name the attribute as “SelectedRow”. Set type as String and make sure that updatable section is set as “Always”.

4. Click to Ok and close the windows. Then click OK button and wizard will be closed. At this point transient attribute should be created in view object. 5. Click to the page and right click to the advancedTable(DmlAdvanceTableRN ) region. Select new->multipleSelection.

6. Select multipleSelection1 which is generated by Jdeveloper under the advanced table region. Select View Attribute value as “SelectedRow”. 

Page 17: OAF Table Region DML Operations

  7. Open view object edit wizard. Choose Java section from left menu and check “View Row Class “<YourVoName>RowImpl” – Generate Java File”. Click OK button.

8. Open application module java file and add the following method.removeSelectedRowsJava

123456789101112131

     public void removeSelectedRows() {        //Find view object in application module        OAViewObject vo = (OAViewObject)getXxOafAnilPersonelEOVO1();        //create a row list        java.util.List<Row> removeList = new ArrayList<Row>();        //get the row count from view object        int rowCount = vo.getFetchedRowCount();        if (rowCount > 0) {            //create a row object from voRowImpl class.            XxOafAnilPersonelEOVORowImpl row = null;            //Create a RowSetIterator from view object. Set it start as 0 and range as rowCount            RowSetIterator iter = vo.createRowSetIterator("Iter");            iter.setRangeStart(0);            iter.setRangeSize(rowCount);            for (int i = 0; i < rowCount; i++) {                row = (XxOafAnilPersonelEOVORowImpl)iter.getRowAtRangeIndex(i);

Page 18: OAF Table Region DML Operations

4151617181920212223242526272829303132333435

                if (row != null) {                    //check whether row is selected or not. If selected, add it to the list.                    if ("Y".equals(row.getSelectedRow())) {                        removeList.add(row);                    }                }            }            //always close row set iterator            iter.closeRowSetIterator();                        //remove rows one by one            for (Row deleteRow : removeList) {                deleteRow.remove();            }                    }    } 

 Not:  Please pay attention to iterator usage. You can move between view object rows with vo.next method. However it will change the current row in view object and that is not a thing we always want.9.Open the page structure and add a button under TableActionsRN. Set the following values:

Page 19: OAF Table Region DML Operations

ID ITEM STLE PROMPT ACTION TYPE EVENT

DeleteSelectedRows button Seçili Satırları Sil firePartialAction deleteSelectedRows

10. Open controller object java file and change processFormRequest method with the following code.processFormRequestJava

12345678910111213141516

   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processFormRequest(pageContext, webBean);    OAApplicationModule am = pageContext.getApplicationModule(webBean);    if (pageContext.getParameter("Apply") != null) {        am.invokeMethod("apply");    }    else if ("addNewRow".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {        am.invokeMethod("addNewRow");    }        else if ("deleteSelectedRows".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {        am.invokeMethod("removeSelectedRows");    }  } 

Page 20: OAF Table Region DML Operations

11. Final structure of page: 12. Run the page and test the

results.

This tutorial covers many basic and important topics in OAF. I hope it will prove some useful information for EBS developers.Regards,AnilTags: oracle apps, oracle, oaf, oa framework, oaf table, advanced table, row selection, entity object, application module,add row, view object

Calling Stored Procedures or Functions from OAF PageTo invoke a stored procedure or function from within an entity object or an application module, you need to follow below steps:1. Create a CallableStatement with the PL/SQL block containing the stored procedure or function invocation2. Bind any parameters ( IN or OUT )

Page 21: OAF Table Region DML Operations

3. Execute the statement.4. Optionally retrieve the values of any OUT parameters or return value of function5. Close the statement.

I will illustrate previous steps in below examples

1-Stored Procedure with OUT parameter 

public void testStoredProcedure() { OADBTransaction txn = getDBTransaction(); CallableStatement callableStatement = txn.createCallableStatement("begin xxx_procedure(:1, :2); end;",OADBTransaction.DEFAULT); try { callableStatement.registerOutParameter(2, Types.VARCHAR); callableStatement.setString(1, "mahmoud"); String outParamValue = null; callableStatement.execute(); outParamValue = callableStatement.getString(1); callableStatement.close(); } catch (SQLException sqle) { callableStatement.close(); } }

2- Stored Function

public void testFunction() { OADBTransaction txn = getDBTransaction(); CallableStatement callableStatement = txn.createCallableStatement("begin :1 := xx_function(:2); end;",OADBTransaction.DEFAULT); try {

Page 22: OAF Table Region DML Operations

callableStatement.registerOutParameter(1, Types.VARCHAR); callableStatement.setString(1, "mahmoud"); String outParamValue = null; callableStatement.execute(); outParamValue = callableStatement.getString(1); callableStatement.close(); } catch (SQLException sqle) { callableStatement.close(); } } Mahmoud Ahmed El-Sayed

Usage of Record Type in Callable Statementwrite below code under processFormRequest  based on your conditions.we can process record types using below Process 

Import statement:import oracle.jdbc.driver.OracleCallableStatement;import oracle.sql.ARRAY;import oracle.sql.ArrayDescriptor; import java.sql.SQLException;

String str[] = new String[30];

       for(int i = 0; i < 10; i++)

       try

     {

        str[i] = i;       }      catch(Exception e)

    {          str[i] = null;    }

  try {

   ArrayDescriptor segvaldesc = ArrayDescriptor.createDescriptor("SEGMENT_VALUES", connection);

   ARRAY segval = new ARRAY(segvaldesc, connection, str);

Page 23: OAF Table Region DML Operations

  OracleCallableStatement ocs = (OracleCallableStatement)connection.prepareCall("Begin      XXHR_SIT_VALIDATION_PKG.VALIDATE_RECORD    (p_sit_code=>:1,p_segment=>:2,p_person_id=>:3,p_employee_id=>:4,p_message=>:5); end;");

  ocs.setString(1, s_struc_code);  ocs.setARRAY(2, segval);  ocs.setString(3, v_person_id);  ocs.setString(4, v_emp_id);  ocs.registerOutParameter(5, 12);  ocs.execute();

  v_message = ocs.getString(5);  ocs.close(); }catch(SQLException sqlexception){throw new OAException("Error " + sqlexception.getMessage(), (byte)2);}==========================

public voic initEmpFuncVO(String deptnoStr){ EmpfuncVOIMPL vo=getEmpFuncVO1(); vo.clearcache(); vo.setWhereClause(null); vo.setWhererClauseParam(0,deptnoStr); vo.executeQuery();}

public void deleteEmpRow(){ Empvoimpl vo=getempvo1(); EmpVORowImpl row=null; Row rows[]=vo.getFilteredRows("SelectedFlag","Y"); for(int i=0;i<rows.length;i++) { row=(EmpVORowImpl)rows(i); String sql="BEGIN xxcus_oaf_emp_utils.delete_emp(p_emp_id=>:1); END;"; CallableStatement cstmt=getOADBTransaction().createCallableStatement(sql,1);

try { cstmt.setInt(1,row.getEmpno().intValue()); cstmt.execute(); cstmt.close();

Page 24: OAF Table Region DML Operations

}catch(SQLException e) { //TODO } row.remove(); } //loop end getOADBTransaction().commit(); throw new OAException("Deleted the sel rows",OAException.CONFORMATION); }

===========================================================================

PopUp Window Using PopupBean Programetically

In Process Request

OAPopupBean popupBean =(OAPopupBean)createWebBean(pageContext,POPUP_BEAN,null,"myPopup");//Set the following properties on the pop-up:popupBean.setID("myPopup");popupBean.setUINodeName("myPopup");String popupRegion= "/oracle/apps/fnd/framework/toolbox/labsolutions/webui/TestEmpDetailsRN" ;popupBean.setRegion(popupRegion);popupBean.setHeight("130");popupBean.setWidth("320"); popupBean.setTitle("Test");popupBean.setType(EMBEDDED_POPUP); /* Embedded type */

Alert Using JavaScript in OAF

    if(pageContext.getParameter("SubmitButton")!=null)    {      StringBuffer l_buffer = new StringBuffer();      l_buffer.append("javascript:alert('hello')");      pageContext.putJavaScriptFunction("SomeName",l_buffer.toString());    }

Page 25: OAF Table Region DML Operations

Color The Item Based On Employee Position in Advanced table

Step 1:Create EO Based VO i.e,EMPVOSELECT EMPEo.EMPNO,        EMPEo.ENAME,        EMPEo.JOB,        EMPEo.MGR,        EMPEo.HIREDATE,        EMPEo.SAL,        EMPEo.COMM,        EMPEo.DEPTNO,        EMPEo.CREATION_DATE,        EMPEo.CREATED_BY,        EMPEo.LAST_UPDATE_DATE,        EMPEo.LAST_UPDATE_LOGIN,        EMPEo.LAST_UPDATED_BY,        EMPEo.ROWID,DECODE (EMPEo.JOB,'MANAGER', '1','2') colorFROM EMP EMPEo

Step 2:Under Custom.xss 

add Follwing code<style name="For_Bold"><property name="font-weight">bold</property><property name="font-size">10pt</property></style>

<style selector=".1"><includeStyle name="DefaultFamily"/><property name="font-size">11pt</property><property name="font-weight">Bolder</property><property name="color">#FFFF00</property><property name="text-indent">3px</property><property name="background-color">#FF0000</property>

Page 26: OAF Table Region DML Operations

</style>

<style selector=".2"><includeStyle name="DefaultFontFamily"/><property name="font-size">11pt</property><property name="font-weight">Bolder</property><property name="color">#FFFF00</property><property name="text-indent">3px</property><property name="background-color">#003399</property></style> 

the path of the custom.xss is in $OA_HTML/cabo/Styles/custom.xss

Under Process Request:    OAApplicationModule am=( OAApplicationModule)       pageContext.getApplicationModule(webBean);    EMPVOImpl vo=am.getEMPVO1();    vo.executeQuery();    OAAdvancedTableBean table = (OAAdvancedTableBean)webBean.    findIndexedChildRecursive("region2");    OAColumnBean ejobcol = (OAColumnBean)webBean.    findIndexedChildRecursive("column1");    OAMessageTextInputBean job = (OAMessageTextInputBean)ejobcol.    findIndexedChildRecursive("item1");--for which item you wanted color    OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(job,"Color");    job.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);

O/P will be like: 

Export Selected Rows into Excel File1)Create ViewObject eg: EmpVOQuery:Select empno,ename,sal from scott.emp

2)Create Table by Region Using Wizard or manually with multiple Selection Option.3)Create Transient attribute in EmpVO for Multiple Selection Option.i.e,xxselect type:String.4)Create button  or Submit Button any where depend on The Requirement .   Id:ExportBtn

Page 27: OAF Table Region DML Operations

  Prompt:Export  Event:Export5)Create a Controller under PageLayoutRN.

Write Below Code

public class EmpCO extends OAControllerImpl{  public static final String RCS_ID="$Header$";  public static final boolean RCS_ID_RECORDED =        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  public void processRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processRequest(pageContext, webBean);       EmpVOImpl vo=(EmpVOImpl )pageContext.getApplicationModule(webBean).findViewObject("EmpVO1");    vo.executeQuery();  }

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)  {    super.processFormRequest(pageContext, webBean);    if("Export".equals(pageContext.getParameter(EVENT_PARAM)))    {    EmpVOImpl vo = (EmpVOImpl)pageContext.getApplicationModule(webBean).findViewObject("EmpVO1");      EmpVORowImpl row=(EmpVORowImpl)vo.first();      Row[] row1=vo.getFilteredRows("xxselect","Y");    try    {

    HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();    response.setContentType("application/txt");    response.setHeader("Content-Disposition","attachment; filename=" + "Employee Trouble Call Report" + ".csv");    PrintWriter pw = null;    pw = response.getWriter();

Page 28: OAF Table Region DML Operations

    //Writing the headers    pw.write("Emploee Number");    pw.write(",");    pw.write("Employee Name");    pw.write(",");    pw.write("Salary");       pw.write("\n");    // getting table data    Row row2=null;    System.out.println(row1.length);       for(int i=0;i<row1.length;i++)//Read Selected Rows       {       row2=row1[i];       String dept_name= row2.getAttribute("Empno").toString();        String emp_name=row2.getAttribute("Ename").toString();        String Salary=row2.getAttribute("Sal").toString();         if(dept_name !=null) // for null handling in the code         {         pw.write(dept_name);         }         else         {         pw.write(" ");         }//      emp_name = emp_name.replaceAll(",",".");           pw.write(",");           if(emp_name!=null)           {          pw.write(emp_name);           }           else           {             pw.write("");           }         pw.write(",");//next cell         if(Salary!=null)         {         pw.write(Salary);         }         else         {

Page 29: OAF Table Region DML Operations

           pw.write("");         }           pw.write("\n");//next line       }       pw.write(" ");    pageContext.setDocumentRendered(false); //mandatory    pw.flush(); //exporting data    pw.close();

    }    catch(Exception e)    {    e.printStackTrace();    }    }  }}

Export Data from Excel file to DataBase tablesStep 1: Create FileUpload Item  in Page

            Id:FileUploadItem

            Prompt:FileUpload

            DataType:Blob

Step 2:Create  a Submit Button

           Id:Go

          Prompt:Go

Step 3:Create a submit Button

           Id:Update

           Prompt:Update

           Event:update

Step 4:Write Following Code in controller i.e, attached to a page.

Page 30: OAF Table Region DML Operations

 import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import oracle.apps.fnd.common.VersionInfo;

import oracle.apps.fnd.framework.OAApplicationModule;

import oracle.apps.fnd.framework.OAException;

import oracle.apps.fnd.framework.server.OAViewObjectImpl;

import oracle.apps.fnd.framework.webui.OAControllerImpl;

import oracle.apps.fnd.framework.webui.OAPageContext;

import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.cabo.ui.data.DataObject;

import oracle.jbo.Row;

import oracle.jbo.domain.BlobDomain;

/**

 * Controller for ...

 */

public class FileUploadCO extends OAControllerImpl

{

  public static final String RCS_ID="$Header$";

  public static final boolean RCS_ID_RECORDED =

        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

Page 31: OAF Table Region DML Operations

  /**

   * Layout and page setup logic for a region.

   * @param pageContext the current OA page context

   * @param webBean the web bean corresponding to the region

   */

  public void processRequest(OAPageContext pageContext, OAWebBean webBean)

  {

    super.processRequest(pageContext, webBean);

  }

  /**

   * 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=(OAApplicationModule)pageContext.getApplicationModule(webBean);

    OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject("DemoVO1");

    if (pageContext.getParameter("Go")!=null)

    {

Page 32: OAF Table Region DML Operations

    DataObject fileUploadData =(DataObject)pageContext.getNamedDataObject("FileUploadItem");

    String fileName = null;

    String contentType = null;

    Long fileSize = null;

    BlobDomain uploadedByteStream = null;

    BufferedReader in = null;

     

    try

    {

    fileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");

    contentType =(String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");

    uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, fileName);

    in = new BufferedReader(new InputStreamReader(uploadedByteStream.getBinaryStream()));

     fileSize = new Long(uploadedByteStream.getLength()); 

    System.out.println("fileSize"+fileSize);

    }

    catch(NullPointerException ex)

    {

    throw new OAException("Please Select a File to Upload", OAException.ERROR);

    }

    try{     

    //Open the CSV file for reading  

    String lineReader="";

    long t =0;

Page 33: OAF Table Region DML Operations

     

     

    String[] linetext;

     

     

    while (((lineReader = in.readLine()) !=null) ){

     

     

    //Split the deliminated data and

    if (lineReader.trim().length()>0)

    {

    System.out.println("lineReader"+lineReader.length());

    linetext = lineReader.split(",");

    t++;  

    

    if (!vo.isPreparedForExecution()) {

    vo.setMaxFetchSize(0);

    vo.executeQuery();

    }

    Row row = vo.createRow();

    System.out.println("Column1->"+linetext[0]);

    row.setAttribute("VendorName", linetext[0]);

    row.setAttribute("Segment1",linetext[1]);

    row.setAttribute("VendorId",linetext[2]);

    

Page 34: OAF Table Region DML Operations

    vo.last();

    vo.next();

    vo.insertRow(row);

    }

     }

    }

     

     

    catch (IOException e)

    {

     e.printStackTrace();

    }

    }

    if ("update".equals(pageContext.getParameter(EVENT_PARAM))) {

    am.getOADBTransaction().commit();

    throw new OAException("Uploaded SuccessFully",OAException.CONFIRMATION);

     

     

    }

    }

    }

    

useful scripts in OAF

JPX import in Unix Environment

Page 35: OAF Table Region DML Operations

java oracle.jrad.tools.xml.importer.JPXImporter $JAVA_TOP/TestProject.jpx -username $APPS_NAME -password $APPS_PASSWORD -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=<HOSTNAME>)(Port=<port number>)) (CONNECT_DATA=(SID=<SID>)))"

XML Import in Unix Environment

java oracle.jrad.tools.xml.importer.XMLImporter $JAVA_TOP/xxmhp/oracle/apps/per/loan/webui/TestPG.xml --rootdir $JAVA_TOP username <user name> -password <password> -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<hostname>)(PORT=<port number>))(CONNECT_DATA=(SID=<SID>)))"

XML Import in Windows Environment

import d:\Jdevloper\jdevhome\jdev\myprojects\xx\oracle\apps\per\webui\EmployeePG.xml -rootdir d:\jdevhome\jdev\myprojects -username apps -password apps -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<hostname>)(PORT=<port number>))(CONNECT_DATA=(SID=<SID>))))

JPX import in Windows Environment

jpximport d:\Employee.jpx -userId 1 -username apps -password apps -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<hostname>)(PORT=<port number>))(CONNECT_DATA=(SID=<SID>))))"

JSP Compilation in Unix Environment

Move your JSP into OA_HTML Directory and run below commands to Compile JSP. Compiled JSP will create respected JSP Class file in $COMMON_TOP/_pages

11i Environment

$JTF_TOP/admin/scripts/ojspCompile.pl --compile -s 'abcd.jsp' --flush

R12 Environment

$FND_TOP/patch/115/bin/ojspCompile.pl --compile -s 'abcd.jsp' --flush