Search This Blog

Saturday, March 19, 2016

17. OAF Entry Master Detail Page

OAF Master-Detail page will be covered in this tutorial. In order to make a master-detail OAF page, we need to use Association and View Link BC4J objects for keeping data integrity.
1. Run below sql in order to create tables, synonyms and sequences. Please pay attention to foreign key constraint between two tables. This constraint provides both data integrity and automatic generation of Association and View Link objects in JDeveloper.



create table xxntc.xx_teams (
    team_id             number primary key,
    team_name           varchar2(100),
    budget              number,
    establish_date      date,
    creation_date       date,
    created_by          number,
    last_update_date    date,
    last_updated_by     number,
    last_update_login   number
);

create public synonym xx_teams for xxntc.xx_teams;

create sequence xxntc.xx_teams_s start with 1;

create table xxntc.xx_players (
    player_id           number primary key,
    team_id             number,
    name                varchar2(100),
    surname             varchar2(100),
    salary              number,
    position            varchar2(100),
    creation_date       date,
    created_by          number,
    last_update_date    date,
    last_updated_by     number,
    last_update_login   number,
    constraint xx_players_fk
    foreign key (team_id)
    references xxntc.xx_teams (team_id)    
);

create public synonym xx_players for xxntc.xx_players;

create sequence xxntc.xx_players_s start with 1;


2. Open a JDeveloper which has already prepared for initial setup. Right Click to your project and click New. Go To Business Tier-> ADF Business Componenets -> Business Components from Tables and click Ok button.

Image1:C:\Users\egov\Desktop\1.jpg

3.Organize your entity objects.
Image2:
C:\Users\egov\Desktop\2.jpg

4.Organize your view objects.
Image3:
C:\Users\egov\Desktop\3.jpg

5.Keep going without creating read-only view objects.
Image4:
C:\Users\egov\Desktop\4.jpg

6. Create application module and add your view objects into it.
Image5:
C:\Users\egov\Desktop\5.jpg
7. Final structure for BC4J model:
Image6:C:\Users\egov\Desktop\6.jpg

8. Right click to XxPlayersFkAssoc  association and click edit.
Image7:C:\Users\egov\Desktop\7.jpg

9.In order to automatically set TeamId for child entity, there must be a composite relationship between master and detail entity objects. In order to do this, check composite association.
Image8:C:\Users\egov\Desktop\8.jpg

10. Create a new OAF page with following steps.
Image9:C:\Users\egov\Desktop\9.jpgC:\Users\egov\Desktop\10.jpg
Image10:
Image11: C:\Users\egov\Desktop\11.jpg

11. Define a controller object for your page.
Image12:C:\Users\egov\Desktop\12.jpg

12. Edit PageLayout Region properties:
ID
Window Title
Title
AM Definition
PageLayoutRN
 Master-Detail Page
 Master-Detail Page
 xxntc.oracle.apps.per.md.server.XxMdAM
13. Add two new region to page layout region and edit their properties with below information.
ID
Item Style
Text
MasterHdrRN
header
 Teams

ID
Item Style
Text
DetailHdrRN
header
 Players


14. Add a new region using wizard into MasterHdrRN.

Image13:C:\Users\egov\Desktop\13.jpg
Image14:C:\Users\egov\Desktop\14.jpg
Image15:C:\Users\egov\Desktop\15.jpg
Image16:C:\Users\egov\Desktop\16.jpg
Image17:C:\Users\egov\Desktop\17.jpg

15. Add a new region using wizard into DetailHdrRN .

Image18:C:\Users\egov\Desktop\18.jpg
Image19:C:\Users\egov\Desktop\19.jpg
Image20:C:\Users\egov\Desktop\20.jpg
Image21:C:\Users\egov\Desktop\21.jpg
Image22:C:\Users\egov\Desktop\22.jpg

16. Add tableActions into XxPlayersEOVO2 table region.
Image23:C:\Users\egov\Desktop\23.jpg

17. Add New Item to Region1 under table actions and edit item properties with below information.
Image24:C:\Users\egov\Desktop\24.jpg

ID
Item Style
Prompt
Action Type
Event
AddPlayer
 button
 Add Player
 firePartialAction
 addPlayer


19. Add a new region into PageLayoutRN and edit properties with below information.
ID
Region Style
PageButtonBarRN
 pageButtonBar


20. Add a new item into PageButtonBarRN and edit properties.
ID
Item Style
Prompt
Apply
 submitButton
 Save


21. Create and Ovewwrite create methods for entity object java files XxPlayersEO and XxTeamsEO.
Image25:C:\Users\egov\Desktop\25.jpg
Image26:C:\Users\egov\Desktop\26.jpg

22. Make the following code changes.
MasterDetailPGCO.java process request
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if (!pageContext.isFormSubmission()) {
am.invokeMethod("createEmptyTeam");
}
}

MasterDetailPGCO.java - processFormRequest
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if ("addPlayer".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {
am.invokeMethod("addPlayer");
}
else if (pageContext.getParameter("Apply") != null) {
am.invokeMethod("commit");
}
}


XxTeamsEOImpl.java
public void create(AttributeList attributeList) {
super.create(attributeList);
OADBTransactionImpl transaction = (OADBTransactionImpl)getOADBTransaction();
Number TeamId = transaction.getSequenceValue("XXNTC.XX_TEAMS_S");
setTeamId(TeamId);
}


XxPlayersEOImpl.java
public void create(AttributeList attributeList) {
super.create(attributeList);
OADBTransactionImpl transaction = (OADBTransactionImpl)getOADBTransaction();
Number PlayerId = transaction.getSequenceValue("XXNTC.XX_PLAYERS_S");
setPlayerId(PlayerId);
}


XxMdAMImpl.java
public void createEmptyTeam() {
XxTeamsEOVOImpl vo = getXxTeamsEOVO1();
if (!vo.isPreparedForExecution()) {
vo.executeQuery();
}
Row row = vo.createRow();
vo.insertRow(row);
row.setNewRowState(Row.STATUS_INITIALIZED);
}


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


public void addPlayer() {
OAViewObject vo = (OAViewObject)getXxPlayersEOVO2();
if (!vo.isPreparedForExecution()) {
vo.executeQuery();
}
Row row = vo.createRow();
vo.insertRow(row);
row.setNewRowState(Row.STATUS_INITIALIZED);
}


23. Run the page and test it.
C:\Users\egov\Desktop\27.jpg
24. Check the results.

select * from xxntc.xx_teams;

select * from xxntc.xx_players



Reference: http://www.anilaltunkan.com/en/oracle-3/oracle-application-framework-oracle/oaf-master-detail-page/

No comments:

Post a Comment