2-Oracle Application Framework (OAF) Training Guide - Update, Delete Insert, Validation
2-Oracle Application Framework (OAF) Training Guide - Update, Delete Insert, Validation
Contents
1- Job and Position DML ................................................................................................. 1
1- Update.................................................................................................................................. 1
2- Delete ................................................................................................................................... 4
A.Delete Position ............................................................................................................ 4
B.Delete Job and its related Positions ........................................................................... 6
3- Insert ................................................................................. Error! Bookmark not defined.
A. Insert Position............................................................................................................. 9
A. Insert Job ................................................................................................................... 11
View Object..................................................................................................................... 21
Description
1- Update
As Default we will create Public method in AM and call it from CO when action fired on page
public void Save()
{
//Commeit changes to DB
getOADBTransaction().commit();
}
5
6
Click on Page (XxJobsAndPositionsPG.xml) and Right Click on MainRN New New Region
ID ButtonsRN
Region Syle pageButtonBar
9
10
11
ID Save
Item Style submitButton
Prompt Save
Action Type fireAction
Event Save
12
13
14
15
17
18
No Run Page query change in any field press save query again
Query
Press save
Query Again
2- Delete
20
A.Delete Position
21
22
23
24
25
26
27
28
29
30
32
33
34
ID DeleteLink
Item Style Link
Action Type fireAction
Event DeletePosition
Right Click on DeleteLink
35
36
37
38
ID DeletePositionImg
Prompt Delete
Image URL deletearea_enabled.gif
All images will be find in root (<Jdeveloper path>\jdevhome\jdev\myhtml\OA_MEDIA)
You can put your own image and use it
41
42
43
44
45
46
47
48
50
51
52
Create Two Public method in AM one for delete positions by jobid and other delete job by ref like previous
First One
public void DeletePositionByJobId(String pJobId)
{
//Define array and get all rows in XxPositionsVO1
Row pPositionsVORow[] =getXxPositionsVO1().getAllRowsInRange();
//Loop on this rows and delete row with job id passed in method "pJobId"
for(int i=0;i<pPositionsVORow.length;i++)
{
//Define ViewObjectRow Variable and get in it row by row
XxPositionsVORowImpl rowi=(XxPositionsVORowImpl)pPositionsVORow[i];
//Check if job id in this row equal to variable if yes then remove and continue loop
if (rowi.getJobId().toString().equals(pJobId))
{
rowi.remove();
}
}
}
53
54
55
56
Second one
In import section
import xx.oracle.apps.per.xxhr.server.XxJobsVORowImpl;
public void DeleteJobByRowReff(String pRowReference)
{
//Define ViewObjectRow Variable and get in it current row
XxJobsVORowImpl pJobVORow = (XxJobsVORowImpl)findRowByRef(pRowReference);
//Define String to get job id
String pJobId = pJobVORow.getJobId().toString();
//invoke method that delete position with jobid
DeletePositionByJobId(pJobId);
//Remove this row
pJobVORow.remove();
//Make first row selected
getXxJobsVO1().first().setAttribute("SelectFlag","Y");
}
58
59
60
ID DeleteJobLink
Item Style Link
Action Type fireAction
Event DeleteJob
Right Click on DeleteJobLink
61
62
63
64
65
ID DeleteJobImg
Prompt Delete
Image URL deletearea_enabled.gif
Open CO (Double Click file XxJobsAndPositionsCO.java)
if (pAction.equals("DeleteJob"))
{
//Define String variable get in it row refernce (Like Key) which action fire on it
String RowReference =
pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
//Define Serializable (List of parameters) and put row refernce in it
Serializable[] paramList = { RowReference };
//Invoke method we create in Application Module and pass to it parameters
pXxHrAm.invokeMethod("DeleteJobByRowReff",paramList);
}
67
68
69
70
71
72
73
A. Insert Position
75
76
77
ID AddPosition
Item Style submitButton
Prompt Add New Position
Action Type fireAction
Event AddPosition
Create Public method in AM
Put
import oracle.apps.fnd.framework.OAException;
In import scetion
public void IniPositionRecord()
{
//Check that there are records in JObVO to can create deatil for it
if (!getXxJobsVO1().isPreparedForExecution())
{
throw new OAException("Please select job record first",OAException.ERROR
);
}else
{
int RowCount = getXxJobsVO1().getRowCount();
if (RowCount == 0)
{
throw new OAException("Please select job record
first",OAException.ERROR);
}else
{
//Define ViewObject Variable and get in it XxJobsVO1 View Object
OAViewObject pPositionsVO = getXxPositionsVO1();
//Check if VO of able to create record
if (!pPositionsVO.isPreparedForExecution())
{
//if not prepared
pPositionsVO.setMaxFetchSize(0);
pPositionsVO.executeQuery();
pPositionsVO.setMaxFetchSize(-1);
}
pPositionsVO.last();
pPositionsVO.next();
Row pPositionsVORow = pPositionsVO.createRow();
pPositionsVO.insertRow(pPositionsVORow);
//Get position Id sequense like XX_POSITION_ID_SEQ.NextVal in Sql and
set Attribute PositionId
String pNewPositionId =
getOADBTransaction().getSequenceValue("XX_POSITION_ID_SEQ").toString();
pPositionsVORow.setAttribute("PositionId", pNewPositionId);
79
80
In CO
if (pAction.equals("AddPosition"))
{
//Invoke method we create in Application Module to create new record in position VO
pXxHrAm.invokeMethod("IniPositionRecord");
}
81
82
83
84
A. Insert Job
86
87
88
89
90
91
ID AddJob
Item Style submitButton
Prompt Add New Job
Action Type fireAction
Event AddJob
Create Public method in AM
public void IniJobRecord()
{
//Define ViewObject Variable and get in it XxJobsVO1 View Object
OAViewObject pJobsVO = getXxJobsVO1();
//Check if VO of able to create record
if (!pJobsVO.isPreparedForExecution())
{
//if not prepared
pJobsVO.setMaxFetchSize(0);
pJobsVO.executeQuery();
pJobsVO.setMaxFetchSize(-1);
}
pJobsVO.last();
93
94
In CO
if (pAction.equals("AddJob"))
{
//Invoke method we create in Application Module to create new record in position VO
pXxHrAm.invokeMethod("IniJobRecord");
}
95
96
Description
Delete All data in XX_JOBS and XX_POISTIONS And run OA Project DML Script.sql Again
Set the four fields under PoistionTable and JobTable required Yes
Name XX_POSITION_DATE_VALIDATION
Language US
Application Human Resources
Current Message Text In Poistion table effective start date can not be greater than effective end date
9
10
This will validate that if effective start date can not be greater that effective end date
In Import Section
11
import oracle.apps.fnd.framework.OAAttrValException;
import oracle.apps.fnd.framework.OARowValException;
import oracle.jbo.domain.Timestamp;
import oracle.jbo.Row;
Search for public void setEffectiveStartDate
This is metod that responsible to set effective start date attribute in EO
Delete setAttributeInternal(EFFECTIVESTARTDATE, value);
And write
if (value != null)
{
Date pEffectiveEndDate =getEffectiveEndDate();
if (pEffectiveEndDate != null)
{
Timestamp pEffectiveStartDateTime = new Timestamp(value);
Timestamp pEffectiveEndDateTime = new Timestamp(pEffectiveEndDate);
if (pEffectiveEndDateTime.getTime()< pEffectiveStartDateTime.getTime() )
{
throw new OARowValException (
getEntityDef().getFullName(), // entity full definition name
getPrimaryKey(), // entity object primary key
"PER", // Message application short name
"XX_POSITION_DATE_VALIDATION"); // Message name
}else
{
setAttributeInternal(EFFECTIVESTARTDATE, value);
}
}else
{
setAttributeInternal(EFFECTIVESTARTDATE, value);
}
}else
{
setAttributeInternal(EFFECTIVESTARTDATE, value);
}
12
13
15
16
Now try to update dates in position or insert new record and save
If you need to make this validation after enter data and press tab
You need to set the two fields (effective start date and effective end date )
Action Type fireAction
Event PoistionValidateDate
No need to handle this action in CO and AM as what we need in this case only to fire any action to refresh page
which make the http to send data to VO then to EO and our validation will fire
The action we put will fire when data changed inside fild and cursour is go out of field like post_change in forms
17
18
Like the position dates validation but you need to create a new meesage (HomwWork)
19
22
23
24
25
Delete All data in XX_JOBS and XX_POISTIONS And run OA Project DML Script.sql Again
Define Message
Name XX_JOB_HEADCOUNT_VALIDATE
Language US
Application Human Resources
Current Message Text In Job table job headcount cannot be less than total positions headcount
In file XxJobsEOImpl.java
Put
import xx.oracle.apps.per.xxhr.schema.server.XxPositionsEOImpl;
in import
Before the last Arc write our method
public float xxGetPositionHeadCount()
{
//Define Variable float
float PositionHeadCount =0 ;
//Get Position EO
RowIterator xRowIterator = getXxPositionsEO();
//Loop in this EO and sum headcount in this lines
while (xRowIterator.hasNext())
{
xRowIterator.next();
PositionHeadCount = PositionHeadCount +
Float.valueOf(xRowIterator.getCurrentRow().getAttribute("PositionHeadCount").toString()).floatValue();
}
//return total position head count
return PositionHeadCount;
}
26
27
28
29
31
32
click on JobHeadCount1
33
ActionType fireAction
Event JobHeadCountValidate
Now run page and try to change JobHeadCount to be less than 10
34
35
36
37
38
39
41
42
click on PoisitonHeadCount
43
ActionType fireAction
Event PositionHeadCountValidate
View Object
Step
No.
45
46
Description
View Object Can be build Based on :
1- Entity object in case we will use it in DML like OUR Example
2- Query in case we will use it in LOV(Will be seen later in next Days)
Java Files For VO
1- ViewObject.xml Contain SQL of VO and eneity object based on it also attributes in VO
2- ViewObjectImp all us to deal with View object it self as one component with all its rows.
For Example if you need to get or set attribute in view object you have one method
Getattribute(Attributename) also in set SetAttribute(AttributeName,Value)
3- ViewObjectRowImp it deal with only on row we fetch this row by refrence of rownum or
For Example if you need to get or set attribute in row you have for each attribute two metodh one for ge
and other for set