OAF Master – Detail Örneği
Merhaba,
Bu yazıda OAF sayfalar için Master-Detail yapımını anlatacağım. Master-Detail giriş sayfası yapabilmek için, BC4J Entity Object ve View Object bileşenleri arasında bağ kurulması gerekiyor. Bu bağ View Link ve Association objeleri tarafından sağlanıyor.
1. Aşağıdaki SQL çalıştırılarak örnek için tablo yapıları oluşturulur. Burada dikkat edilmesi gereken nokta iki tablo arasında FOREIGN KEY tanımı yapılmıştır. Bu işlemle hem veri bütünlüğünü güvence altına alır hem de JDeveloper’dan objeleri oluştururken Association ve View Link objelerinin otomatik oluşması sağlanmıştır.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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. Daha önceden ayarları yapılmış JDeveloper projesi açılır ve projeye sağ tıklanıp New seçilir. Business Tier-> ADF Business Componenets -> Business Components from Tables ile devam edilir.
3.Oluşturduğumuz Tablolar için Entity Object seçimleri aşağıdaki gibi düzenlenir.
4.View Object objeleri aşağıdaki gibi düzenlenir.
5.Read-Only View Object kullanılmayacağı için Next ile devam edilir.
6. Application Module oluşturulur ve View Object’leri ekle tiki seçilir.
7. Nihai durumda Model tarafı aşağıdaki gibi şekillenmiştir.
8. Otomatik oluşan XxPlayersFkAssoc nesnesine sağ tıklanır ve Edit ile devam edilir.
9.Master-Detail sayfalarda Detail kaydı Master kayda bağlayan referans alanın otomatik yönetilmesi için Association objesinin Composite olarak değiştirilmesi gerekmektedir. Bunun için aşağıdaki adımla devam edilir.
10. Sayfayı oluşturmak için aşağıdaki adımlar sırasıyla uygulanır.
11. Oluşturulan MasterDetailPG sayfasına Controller Object tanımlanır.
12. Sayfayanın PageLayout Region’ı aşağıdaki gibi düzenlenir.
ID | Window Title | Title | AM Definition |
---|---|---|---|
PageLayoutRN | Master-Detail Page | Master-Detail Page | xxntc.oracle.apps.per.md.server.XxMdAM |
13. PageLayoutRN altına iki adet region eklenir ve özellikleri aşağıdaki gibi güncellenir.
ID | Item Style | Text |
---|---|---|
MasterHdrRN | header | Teams |
ID | Item Style | Text |
---|---|---|
DetailHdrRN | header | Players |
14. MasterHdrRN header region’ı altına yeni bir Region wizard kullanılarak aşağıdaki adımlarla eklenir.
15. DetailHdrRN header region’ı altına yeni bir Region wizard kullanılarak aşağıdaki adımlarla eklenir.
16. XxPlayersEOVO2 table Region’ı altına tableActions eklenir.
17. TableActions altında oluşan Region1 altına yeni bir Item eklenir ve özellikleri aşağıdaki gibi güncellenir.
ID | Item Style | Prompt | Action Type | Event |
---|---|---|---|---|
AddPlayer | button | Add Player | firePartialAction | addPlayer |
19. PageLayoutRN altına yeni bir Region oluşturulur ve özellikleri aşağıdaki gibi değiştirilir.
ID | Region Style |
---|---|
PageButtonBarRN | pageButtonBar |
20. PageButtonBarRN altına yeni bir item eklenir ve özellikleri aşağıdaki gibi güncellenir.
ID | Item Style | Prompt |
---|---|---|
Apply | submitButton | Save |
21. XxPlayersEO ve XxTeamsEO entity objectleri java dosyasına create fonksiyonu oluşturulur.
22. Aşağıdaki kod düzenlemeleri yapılır.
MasterDetailPGCO.java
1 2 3 4 5 6 7 8 9 10 |
public void processRequest(OAPageContext pageContext, OAWebBean webBean) { super.processRequest(pageContext, webBean); OAApplicationModule am = pageContext.getApplicationModule(webBean); if (!pageContext.isFormSubmission()) { am.invokeMethod("createEmptyTeam"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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
1 2 3 4 5 6 7 8 |
public void create(AttributeList attributeList) { super.create(attributeList); OADBTransactionImpl transaction = (OADBTransactionImpl)getOADBTransaction(); Number TeamId = transaction.getSequenceValue("XXNTC.XX_TEAMS_S"); setTeamId(TeamId); } |
XxPlayersEOImpl.java
1 2 3 4 5 6 7 8 |
public void create(AttributeList attributeList) { super.create(attributeList); OADBTransactionImpl transaction = (OADBTransactionImpl)getOADBTransaction(); Number PlayerId = transaction.getSequenceValue("XXNTC.XX_PLAYERS_S"); setPlayerId(PlayerId); } |
XxMdAMImpl.java
1 2 3 4 5 6 7 8 9 10 11 |
public void createEmptyTeam() { XxTeamsEOVOImpl vo = getXxTeamsEOVO1(); if (!vo.isPreparedForExecution()) { vo.executeQuery(); } Row row = vo.createRow(); vo.insertRow(row); row.setNewRowState(Row.STATUS_INITIALIZED); } |
1 2 3 4 5 |
public void commit() { getOADBTransaction().commit(); } |
1 2 3 4 5 6 7 8 9 10 11 |
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. Sayfa çalıştırılır ve test edilir.
24. Sonuçlar test edilir.
1 2 3 4 5 6 7 8 9 10 11 |
set linesize 200; column team_name format a20; column name format a20; column surname format a20; column position format a20; select * from xxntc.xx_teams; select * from xxntc.xx_players; |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
TEAM_ID TEAM_NAME BUDGET ESTABLISH_DATE CREATION_DATE CREATED_BY LAST_UPDATE_DATE LAST_UPDATED_BY LAST_UPDATE_LOGIN ---------- -------------------- ---------- -------------- ------------- ---------- ---------------- --------------- ----------------- 2 GALATASARAY 100000000 01/01/1905 21/09/2014 1732 21/09/2014 1732 2323035 1 row selected. PLAYER_ID TEAM_ID NAME SURNAME SALARY POSITION CREATION_DATE CREATED_BY LAST_UPDATE_DATE LAST_UPDATED_BY LAST_UPDATE_LOGIN ---------- ---------- -------------------- -------------------- ---------- -------------------- ------------- ---------- ---------------- --------------- ----------------- 2 2 ANIL ALTUNKAN 100 SC 21/09/2014 1732 21/09/2014 1732 2323035 3 2 SSS DDD 22 GK 21/09/2014 1732 21/09/2014 1732 2323035 2 rows selected. |