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:
3.Organize your entity objects.
Image2:
4.Organize your view objects.
Image3:
5.Keep going without creating read-only view objects.
Image4:
6. Create application module and add your view objects into it.
Image5:
7. Final structure for BC4J model:
Image6:
8. Right click to XxPlayersFkAssoc association and click edit.
Image7:
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:
10. Create a new OAF page with following steps.
Image9:
Image10:
Image11:
11. Define a controller object for your page.
Image12:
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:
Image14:
Image15:
Image16:
Image17:
15. Add a new region using wizard into DetailHdrRN .
Image18:
Image19:
Image20:
Image21:
Image22:
16. Add tableActions into XxPlayersEOVO2 table region.
Image23:
17. Add New Item to Region1 under table actions and edit item properties with below information.
Image24:
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:
Image26:
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.
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