Create Page to input Employee details


Inserting Data

Create EmpEO

Step1: Right click on Resources and select New Entity Object

image1

 

Step2: Specify the name = EmpEO, Package=trng2.oracle.apps.ak.emp.schema.server (as EO will be in schema.server). Extends Entity will be given if we are customizing so leave blank

Under database objects check “Synonyms” check box so schema objects will be populated to select. It will take some time to generate this list. Select Schema Object as “FWK_TBX_EMPLOYEES”

image2

 

Step3: It shows all available attributes. If required we can create new transient attributes. Transient attributes are those which we can refer only in application but doesn’t exist in database. We can learn more about transient attribute down the line

image3

 

Step4: In next step you can see properties of all attributes. They will by default will get generated as per table definition. Please note that there should be one primary attribute in order to create EO. Also there should who columns

image4

 

Step5: Under Entity Object Class  Generate Java File opt for Accessors, Create method and Remove method

image5

 

Step6: Don’t select anything here as we will be creating VO separately. You can check this if you want to create VO immediately

image6

 

Step7: Click Finish

image7

 

This will create EmpEOImpl.java file with all required fields. This java file will have create method which can be used for defaulting attributes

Here for EMPLOYEE_ID, the value should get from sequence. So we can this attribute with sequence value.

In EmpEOImpl.java  Create method looks as below after writing the required code

public void create(AttributeList attributeList) {

super.create(attributeList);

OADBTransaction transaction = getOADBTransaction();  //gets transaction handler from super class

Number seqNo = transaction.getSequenceValue(“FWK_TBX_EMPLOYEES_S”);

setEmployeeId(seqNo);

}

Note: if this is not handled in EO, we can also implement at VO level at the time new record creation.

OAViewObject vo = (OAViewObject)findViewObject(“EmpVO”);

OARow row = (OARow)vo.first();

row.setAttribute(“EmployeeId”, getOADBTransaction().getSequenceValue(“FWK_TBX_EMPLOYEES_S”).toString());

Creating VO

Step1: Right click on Resources and select New View Object

image8

 

Step2: Specify package = trng2.oracle.apps.ak.emp.server and Name = EmpVO

Extends we can leave blank as we are not extending or customizing existing VO.

VO can be create either with EO or direct SQL Query. Sql Query is used only when we need read only data. As we are using this VO to DML make sure to select “Rows Populated by a SQL Query with”  “Updatable Access through Entity Object”

image9

 

Step3: Select EmpEO from Available list and move to Selected

image10

 

Step4: Select the attributes you want in VO. You can select all or required attributes only. Here selected all attributes except who columns and dff attribute columns

image11

 

Step5: In attribute setting verify default information is correct

image12

 

Step6: In Query page check query generated is correct. You can specify where and order clause if required. To edit the query check “Exper Mode”

image13

 

Step7: You can see view attribute names and can skip this step

image14

 

Step8: You can define custom bind variables if required. You can skip this

image15

 

Step9: You can uncheck Generate Java File under View Object Class unless you want to write code in VO. Check Generate Java File with Accessors for View Row Class

image16

 

This creates EmpVO.xml and EmpVORowImpl.java

image17

 

Creating AM

Step1: Right click on Resources and select New Application Module

image18

 

Step2: Specify package= trng2.oracle.apps.ak.emp.server and Name=EmpAM

Leave Extends blank

image19

 

Step3: Select EmpVO to associate with AM by moving to data model

image20

 

Please note that in Data model you can see VO name as EmpVO1 which is instance of actual VO

Step4: Skip this step by clicking Next

image21

 

Step5: See Generate Java File under Application Module Class is checked

image22

 

Step6: Click Finish

image23

 

This creates EmpAMImpl.java

image24

 

Designing various UI components for EmpCreatePG

Creation of Manager LOV:

Step1: Create common LOV AM which will be used for all LOVs that used in employee application

Right click on resources and New Application Module and specify package = trng2.oracle.apps.ak.emp.lov.server and Name=EmpLovAM

image25

 

Skip next two steps as we are not selecting any VOs now and in last step UNCHECK “Generate Java Files” as there is no need of coding for LOV AMs. Click on finish in last step

image26

 

Step2: Create MgrLovVO. Right click on Resources and select New View Object

Specify package = trng2.oracle.apps.ak.emp.lov.server

Name = MgrLovVO

image27

 

Skip next 3 steps by clicking next and until you get SQL Statement step. Here specify the query as

SELECT full_name AS EMPLOYEE_NAME,

employee_id    AS EMPLOYEE_NUMBER,

email_address

FROM fwk_tbx_employees

WHERE end_date IS NULL

image28

 

Skip all next steps by selecting next until last Java step. Uncheck Generate Java File under MgrLovVOImpl and check Generate Java File under MgrLovVORowImpl and click finish

image29

 

Step3: Add MgrLovVO to EmpLovAM

Right click on EmpLovAM in Application Navigator and select Edit EmpLovAM

image30

 

In Data Model select MgrLovVO from Available View Objects and move to right under Data Model

image31

 

Step4: Create region for LOV

Right click on Resources and select New

Under Web Tier > OA Components select Region

image32

 

Specify Name = MgrLovRN

Package = trng2.oracle.apps.ak.emp.lov.webui

Style=listOfValues

image33

 

Select MgrLovRN in structure pane and set AM Definition = trng2.oracle.apps.ak.emp.lov.server.EmpLovAM

Advanced Search Allowed = True

Scope = Public

image34

 

Right click on MgrLovRN in structure pane and select New > table using Wizard

image35

 

Select Application Module = trng2.oracle.apps.ak.emp.lov.server.EmpLovAM and MgrLovVO1

image36

Set RegionID=MgrNamesTable

image37

Select all columns and move to right

image38

Skip next steps and finally select finish

image39

For EmployeeName and EmployeeNumber in structure pane set Search allowed to True. This makes LOV to have search items automatically on this field

Creating VO for Implementing Message Choice (drop down / poplist) for positions attribute

Step1: Create PositionsVO by right clicking on Resources and select New View Object

Specify Package = trng2.oracle.apps.ak.emp.poplist.server

Name = PositionsVO

image40

Step2: Skip to query step and specify below query

SELECT meaning, lookup_code

FROM fwk_tbx_lookup_codes_vl

WHERE lookup_type = ‘FWK_TBX_POSITIONS’

image41

Step3: Skip to last to step and uncheck Generate Java File for PositionsVOImpl and check Generate Java File for PositionsVORowImpl

image42

Step4: Assign PositionsVO to EmpAM

Right click on EmpAM in Application navigator and select edit EmpAM

image43

And move PositionsVO from available view objects to Data model

image44

 

Designing the Page to Input Employee Details

Creating page to input below employee data

  1. EMPLOYEE_ID (This will be generated automatically and we used sequence in EO to derive this values. So no need of UI item for this attribute)
  2. TITLE
  3. FIRST_NAME
  4. MIDDLE_NAME
  5. LAST_NAME
  6. FULL_NAME
  7. EMAIL_ADDRESS
  8. MANAGER_ID
  9. POSITION_CODE
  10. SALARY
  11. START_DATE

Step1: Right click on Resources and select New

image45

Step2: Select Page under Web Tier > OA Components

image46

Step3: Specify Name=EmpCreatePG and Package= trng2.oracle.apps.ak.emp.webui

image47

Step4: Set default pageLayout region1 properties as below

ID=PageLayoutRN

AM Definition= trng2.oracle.apps.ak.emp.server.EmpAM

Window Title = Create Employee

Title = Employee Details

Warn About Changes = True (this enable page to warn pending transaction when user tries to navigate from this page. Cancel button is exception)

image48

Step5: To Create Page level buttons Apply and Cancel buttons

First select PageLayoutRN in structure pane, then right click and select New > Region

Set properties as below for this region

ID=PageButtons

Region Style=pageButtonBar

Next to add Cancel button, right click on PageButtons in the structure pane and select New > Item. Set or verify properties of this item as below

ID=Cancel

Item Style=submitButton

Attribute Set= /oracle/apps/fnd/attributesets/Buttons/Cancel

Disable Server Side Validation = True (will not perform server validations)

Disable Client Side Validation=True (will not perform client side validations)

Prompt=Cancel

Warn About Changes=False

Next to add Apply button, Right click on PageButtons in structure pane and select NewItem. Set or verify properties of this item as below

ID=Apply

Item Style= submitButton

Attribute Set= /oracle/apps/fnd/attributesets/Buttons/Apply

Prompt=Apply

image49

Step2: Right click on PageLayoutRN of EmpCreatePG in structure panel and select New  Region

Step3: Set region properties as follows

ID=MainRN

Region Style = messageComponentLayout

Step4: Under MainRN create items as below

  1. MessageStyledText (for Employee ID)

ID=EmpId

Data Type = NUMBER

View Instance = EmpVO1

View Attribute = EmployeeId

Prompt = Employee Number

  1. Creating radio buttons for Title

In OAF radio buttons on UI behaves as individual unless you group them programmatically. So that it will allows to select one radio button from group. At run time you need to set name and value for each radio button. Radion buttons having same name will be a group.

  1. messageRadioButton

ID=TitleMr

View Instance = EmpVO1

View Attribute = Title

Prompt = Mr

Checked Value = Mr

  1. messageRadioButton

ID=TitleMrs

View Instance = EmpVO1

View Attribute = Title

Prompt = Mrs

Checked Value = Mrs

  1.     messageRadioButton

ID=TitleMiss

View Instance = EmpVO1

View Attribute = Title

Prompt = Miss

Checked Value = Miss

  1. MessageTextInput

ID=FirstName

Maximum Length=20

View Instance = EmpVO1

View Attribute = FirstName

Prompt = First Name

  1. MessageTextInput

ID=LastName

Maximum Length=40

View Instance = EmpVO1

View Attribute = LastName

Prompt = Last Name

  1. MessageTextInput

ID=EmailAddr

Maximum Length=240

View Instance = EmpVO1

View Attribute = EmailAddress

Prompt = Email

  1. MessageLovInput

ID=MgrId

External LOV = /trng2/oracle/apps/ak/emp/lov/webui/MgrLovRN

(note: if any confirmation message displays select yes)

Maximum Length=240

View Instance = EmpVO1

View Attribute = ManagerId

Prompt = Manager

  1. If we create message lov input, it will have lovMappings under this item in structure panel

image50

By default it will have one mapping item but we can create any number of mapping items. This is used to map item of LOV to current page item

Set lovMap1 properties as below

LOV Region Item = EmployeeNumber

Return Item = MgrId

Criteria Item = MgrId

  1. MessageChoice

ID=Position

Picklist View Definition= trng2.oracle.apps.ak.emp.poplist.server.PositionsVO

(Note: for picklist view def you need to specify actual VO name. for view instance you have to specify instance name like PositionsVO1)

Picklist Display Attribute = Meaning

PIcklist Value Attribute=LookupCode

View Instance = EmpVO1

View Attribute = PositionCode

Prompt = Position

  1. MessageTextInput

ID=Salary

Data Type = NUMBER

View Instance = EmpVO1

View Attribute = Salary

Prompt = Salary

  1. MessageTextInput

ID=StartDate

Data Type = DATE

View Instance = EmpVO1

View Attribute = StartDate

Prompt = Start Date

  1. MessageTextInput

ID=EndDate

Data Type = DATE

View Instance = EmpVO1

View Attribute = EndDate

Prompt = End Date

Create Controller for EmpCreatePG

Step1: Right click on PageLayoutRN region in EmpCreatePG and “Set New Controller”

image51

Step2: Specify Package= trng2.oracle.apps.ak.emp.webui and Name= EmpCreateCO

image52

Row Initialization to create a new record

Before providing values to VO need to create a VO row. This VO row will receive values when form submitted.

 

Step1: Add createEmployee() method in EmpAMImpl.java

public void createEmployee()

{

OAViewObject vo = (OAViewObject)getEmpVO1();

// below initializes the VO used for both update and query as per

// standards but not mandatory

if (!vo.isPreparedForExecution())

{

vo.executeQuery();

}

Row row = vo.createRow();

vo.insertRow(row);

// Required per OA Framework Model Coding Standard but not mandatory

row.setNewRowState(Row.STATUS_INITIALIZED);

}

Step2: Add apply method which is used to commit the pending transaction at AM level

public void apply()

{

getTransaction().commit();

}

Step3: Add rollback method which is used to rollback the pending transaction at AM level

public void rollbackTxn()

{

getTransaction().rollback();

}

Write below code in EmpCreateCO.java in processRequest method to set group for radio buttons used for Title column. It should be under super constructor in processRequest method. Otherwise they will not behave as a group

public void processRequest(OAPageContext pageContext, OAWebBean webBean)

{

super.processRequest(pageContext, webBean);

OAMessageRadioButtonBean rbMr = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMr”);

rbMr.setName(“Title”);

rbMr.setValue(“Mr”);

OAMessageRadioButtonBean rbMiss = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMiss”);

rbMiss.setName(“Title”);

rbMiss.setValue(“Miss”);

OAMessageRadioButtonBean rbMrs = (OAMessageRadioButtonBean) webBean.findChildRecursive(“TitleMrs”);

rbMrs.setName(“Title”);

rbMrs.setValue(“Mrs”);

if (!pageContext.isFormSubmission())

{

//below two statements can also be used to call AM method

//       OAApplicationModule am = pageContext.getApplicationModule(webBean);

//       am.invokeMethod(“createEmployee”,null);

EmpAMImpl am = (EmpAMImpl)pageContext.getApplicationModule(webBean);

am.createEmployee();

}

Step4: In processFormRequest of EmpCreateCO write below code which will execute on clicking apply or cancel button

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)

{

super.processFormRequest(pageContext, webBean);

OAApplicationModule am = pageContext.getApplicationModule(webBean);

if (pageContext.getParameter(“Apply”) != null)

{

am.invokeMethod(“apply”);

}

if (pageContext.getParameter(“Cancel”) != null)

{

am.invokeMethod(“rollbackTxn”);

}

}

To default FullName

In EmpEOImpl.java add highlighted code in below two methods

public void setFirstName(String value) {

if ((value != null) || (!(“”.equals(value.trim()))))

{

String lastName = getLastName();

if (lastName == null)

{

lastName = “”;

}

setFullName(lastName.concat(“, “).concat(value));

}

setAttributeInternal(FIRSTNAME, value);

}

 

public void setLastName(String value) {

if ((value != null) || (!(“”.equals(value.trim()))))

{

String firstName = getFirstName();

if (firstName == null)

{

firstName = “”;

}

setFullName(value.concat(“, “).concat(firstName));

}

setAttributeInternal(LASTNAME, value);

}

Validating start date not to be less than sysdate

In EmpEOImpl.java add highlighted code in below method

public void setStartDate(Date value) {

        validateStartDate(value);

setAttributeInternal(STARTDATE, value);

}

Write validateStartDate method in EmpEOImpl.java as below

OADBTransaction transaction = getOADBTransaction();

long sysdate = transaction.getCurrentDBDate().dateValue().getTime();

long startDate = value.dateValue().getTime();

if (startDate < sysdate)

{

throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,

getEntityDef().getFullName(), // EO name

getPrimaryKey(), // EO PK

“StartDate”, // Attribute Name

value, // Attribute value

“AK”, // Message product short name

“FWK_TBX_T_START_DATE_PAST”); // Message name

}