You are on page 1of 34

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_USERUSER_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 create table hr.xx_oaf_anil_personel (
3
person_id
number,
4
first_name
varchar2(120),
5
last_name
varchar2(120),
6
salary
number,
7
date_of_birth
date,
8
hire_date
date,
9
created_by
number,
1
creation_date
date,
0
last_update_date
date,
1
last_updated_by
number,
1
last_update_login
number
1 );

2
1
3
1
4
1
5
1
6
1
7
1 alter table hr.xx_oaf_anil_personel
8 add constraint xx_oaf_anil_personel_pk primary key (person_id);
1
9
2 create public synonym xx_oaf_anil_personel for hr.xx_oaf_anil_personel;
0
2 create sequence hr.xx_oaf_anil_personel_s
1 start with 1
2 increment by 1
2 minvalue 1
2 nocache
3 nocycle
2 noorder;
4
2
5
2
6
2
7
2
8
2
9
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 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.

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.

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.

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.
column1
ID: FirstNameCol
sortableHeader1
ID: FirstNameColHdr
Prompt: First Name
column2 ID: LastNameCol
sortableHeader2
ID: LastNameColHdr
Prompt: Last Name
column3
ID: SalaryCol

sortableHeader3
ID: SalaryColHdr
Prompt: Salary
column4
ID: DateOfBirthCol
sortableHeader4
ID: DateOfBirthColHdr
Prompt: Date of Birth
column5
ID: HireDateCol
sortableHeader5
ID: HireDateColHdr
Prompt: Hire Date

23. At this step, the page structure should be look like this:
messageTextInput items under columns.

24. Create

FirstNameCol->New->Item
ID

ITEM STYLE

DATA TYPE

MAXIMUM LENGTH

VIEW ATTRIBUTE

FirstName

messageTextInput

VARCHAR2

120

FirstName

LastNameCol->New->Item
ID

ITEM STYLE

DATA TYPE

MAXIMUM LENGTH

VIEW ATTRIBUTE

LastName

messageTextInput

VARCHAR2

120

LastName

SalaryCol->New->Item
ID

ITEM STYLE

DATA TYPE

Salary

messageTextInput

NUMBER

DateOfBirthCol->New->Item

MAXIMUM LENGTH

VIEW ATTRIBUTE

Salary

ID

ITEM STYLE

DATA TYPE

DateOfBirth

messageTextInput

DATE

MAXIMUM LENGTH

VIEW ATTRIBUTE

DateOfBirth

HireDateCol->New->Item
ID

ITEM STYLE

DATA TYPE

HireDate

messageTextInput

DATE

MAXIMUM LENGTH

VIEW ATTRIBUTE

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 object implementation file. Open
<YourVoName>Impl.java file.

Add the following method into view object impl file.


initQuery

Java

1
2 public void initQuery() {
3
executeQuery();
4 }
5
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.
executeOafAnilPersonelVO
Java

1
2 public void executeOafAnilPersonelVO() {
3
XxOafAnilPersonelEOVOImpl vo = getXxOafAnilPersonelEOVO1();
4
if (vo == null) {
5
throw new OAException("Error: XxOafAnilPersonelEOVOImpl is null");
6
}
7
vo.initQuery();
8 }
9
Open controller object again and add the following code in processRequest method.
processRequest
Java

1
2

public void processRequest(OAPageContext pageContext, OAWebBean webBean)

3 {
4
super.processRequest(pageContext, webBean);
5
//get application module object from the context by sending webBean. webBean
6 object represents pageLayoutRegion because controller object is attached to it.
7
OAApplicationModule am = pageContext.getApplicationModule(webBean);
8
//call application module method
9
am.invokeMethod("executeOafAnilPersonelVO");
1 }
0
27. Run the page and test it. Table will be empty since no rows are added into database table.

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

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

ITEM STLE

PROMPT

ACTION TYPE

EVENT

AddNewRow

button

Yeni Satr 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.

4. Open entity object implementation java file.


Change the create method with the following.
create
Java

1
2
3
/**Add attribute defaulting logic in this method.
4
*/
5
public void create(AttributeList attributeList) {
6
super.create(attributeList);
7
//get transaction
8
OADBTransactionImpl transaction =
9 (OADBTransactionImpl)getOADBTransaction();
1
//get next value from sequence in transaction
0
Number PersonId =
1 transaction.getSequenceValue("HR.XX_OAF_ANIL_PERSONEL_S");
1
//set it to primary key
1
setPersonId(PersonId);
2
}
1
3
5. Open application module java file and create addNewRow method.
addNewRow
Java

1
2
3
4
public void addNewRow() {
5
//Find view object from application module
6
OAViewObject vo = (OAViewObject)getXxOafAnilPersonelEOVO1();
7
//unless vo query is executed or if no row has inserted before, setMaxFetchSize
8
to 0
9
if (vo.getFetchedRowCount() == 0) {
1
vo.setMaxFetchSize(0);
0
}
1
//create a row object from view object. At this point execution will jump to entity
1
object create method
1
Row row = vo.createRow();
2
//insert row into view object
1
vo.insertRow(row);
3
//in order to keep row state, set it as initialized.
1
row.setNewRowState(Row.STATUS_INITIALIZED);
4
}
1
5
1
6
6. Open controller object java file and write following code in processFormRequest method.
processFormRequest
Java

1
2
3
4
5
6
7
8
9
1
0
1
1
1
2

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_PAR
AM))) {
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.
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.
apply
Java

1
2 public void apply() {
3
getOADBTransaction().commit();
4 }
5
10. Open controller object java file and change processFormRequest method with the following.
processFormRequest
Java

1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5

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_PAR
AM))) {
am.invokeMethod("addNewRow");
}
}

11. Run the page and test the results.

xx_oaf_anil_personel
Oracle PL/SQL

1
2 select * from xx_oaf_anil_personel;
3

Results:

Multiple Row Delete


1. 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.

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.

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.
removeSelectedRows
Java

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

4
1
5
1
6
1
7
1
8
1
9
2
0
if (row != null) {
2
//check whether row is selected or not. If selected, add it to the list.
1
if ("Y".equals(row.getSelectedRow())) {
2
removeList.add(row);
2
}
2
}
3
}
2
//always close row set iterator
4
iter.closeRowSetIterator();
2
5
//remove rows one by one
2
for (Row deleteRow : removeList) {
6
deleteRow.remove();
2
}
7
2
}
8
}
2
9
3
0
3
1
3
2
3
3
3
4
3
5
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:
ID

ITEM STLE

PROMPT

ACTION TYPE

EVENT

DeleteSelectedRows

button

Seili Satrlar Sil

firePartialAction

deleteSelectedRows

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

1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6

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_PAR
AM))) {
am.invokeMethod("addNewRow");
}
else if
("deleteSelectedRows".equals(pageContext.getParameter(OAWebBeanConstants.EVE
NT_PARAM))) {
am.invokeMethod("removeSelectedRows");
}
}

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,
Anil
Tags: 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 Page
To 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 invocation
2. Bind any parameters ( IN or OUT )
3. Execute the statement.
4. Optionally retrieve the values of any OUT parameters or return value of
function
5. 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 {
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 Statement


write 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);
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();
}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());
}

Color The Item Based On Employee Position in


Advanced table

Step 1:
Create EO Based VO i.e,EMPVO
SELECT 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'
) color
FROM 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>
</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 File


1)Create ViewObject
eg: EmpVO
Query: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
Prompt:Export
Event:Export
5)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();
//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
{
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 tables


Step 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.

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%");

/**
* 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)
{
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;

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]);

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
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

You might also like