7
Nested Application Modules in OA Framework Written by Kishore Ryali Thursday, 14 May 2009 03:59 In one of my old articles on OA Framework extension, I briefly mentioned about Nested Application modules. Today I will explain how Nested Application module can be used. Nested AM is an application module which is under the scope of root application module. Root application module is the AM attached to top region of the page during design time. It maintains the session state and retention level for requests between client and server. Root AM can contain one or more nested AMs which can themselves nest children to any arbitrary level. In this scenario, the root AM has access to all the data/objects held by its children, and all children participate in the same transaction established by the root. How do you create nested application module? Nested application module is created in a similar fashion as any application module. You can create it using wizard in JDeveloper by selecting view objects it uses and code any custom methods in AMImpl class. You can nest an instance of an application module inside another application module in design time or run time. Design-Time Suppose you have two application modules XxRootAM and XxNestedAM in your project. To make XxNestedAM nested to XxRootAM, you reference XxNestedAM in Application Module section of XxrootAM Editor. Below screenshot shows editor and how XxrootAM.xml is added with AppModuleUsage tag to reference XxNestedAM. 1 / 7

nested application modules

Embed Size (px)

Citation preview

Page 1: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

In one of my old articles on OA Framework extension, I briefly mentioned about NestedApplication modules. Today I will explain how Nested Application module can be used. NestedAM is an application module which is under the scope of root application module. Rootapplication module is the AM attached to top region of the page during design time. It maintainsthe session state and retention level for requests between client and server.

Root AM can contain one or more nested AMs which can themselves nest children to anyarbitrary level. In this scenario, the root AM has access to all the data/objects held by itschildren, and all children participate in the same transaction established by the root.

How do you create nested application module?Nested application module is created in a similar fashion as any application module. You cancreate it using wizard in JDeveloper by selecting view objects it uses and code any custommethods in AMImpl class. You can nest an instance of an application module inside anotherapplication module in design time or run time.

Design-Time

Suppose you have two application modules XxRootAM and XxNestedAM in your project. Tomake XxNestedAMnested to XxRootAM, you reference XxNestedAM in Application Module section of XxrootAMEditor. Below screenshot shows editor and how XxrootAM.xml is added with AppModuleUsagetag to reference XxNestedAM.

1 / 7

Page 2: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

 

Run-Time

You use createApplicationModule() method in oracle.jbo.ApplicationModule Interface, tocreate an instance of application module on another application module. For the aboveexample,assuming ram is instance of XxRootAM, below command creates instance nam forXxNestedAM.

OAApplicationModule nam = (OAApplicationModule)ram.createApplicationModule("XxNestedAM", "xxa2f.oracle.apps.icx.icatalog.shopping.server.XxNestedAM");

You have to give full-qualified name of application module as second parameter. You can thenaccess view objects attached to root application module, in nested application module. SupposeXxRootAM has view object XxVO, you can get instance of it in XxNestedAM using

ViewObject vo = nam.findViewObject("XXVO");

Note that XxNestedAM should be created declaratively before it can be nested usingcreateApplicationModule() in run-time.

Why use nested application module?Nested application module promotes reusablility and modularizing business logic into smallerand specific business components. It helps to prevent root application module in growing biggerand become nightmare for maintenance and concurrent development. Starting with release11.5.10, nested application modules are instantiated on an "as needed" basis (in previousreleases, BC4J instantiated all the nested application modules when the containing applicationmodule was created). For example, if you do a findApplicationModule , BC4J will instantiate theobject. If a nested application module is never accessed, it is not created.

More importantly than usual, you can use nested application module to put custom businesslogic in root application module for seeded pages. It is not advisable to extend root applicationmodule. You can still get away with extending root AM until your seeded page doesn't haveLOV fields. If page has LOV fields, root AM extension will cause session time out when clickedon LOV. The error looks similar to

"Error: Cannot Display Page You cannot complete this task because one of the following events caused a loss of page data:Your login session has expired. A system failure has occurred. "

I was stuck up with the same error when I extended root AM in the Part-2 article of Custom

2 / 7

Page 3: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

Defaulting and Validation in iProcurment. So solution for root AM extension is to use nested application module. They come really handyin such scenarios.

Give me an example?In iProcurement, I will add custom logic to print "Requisition Header Id" in console when "Add toCart" button is pressed during requisition creation. Some details of 'About this Page' forNon-Catalog Request page.

Page Name: NonCatalogRequestPGController: NonCatalogRequestCOAM: RequisitionAM

To implement above requirement, I will create custom application module and make it nested toRequisitionAM in Controller. Then I will create printReqHeaderId() method to accessPoRequisitionHeadersVO in custom application module and print Requisition Header Id inconsole.

Steps to use nested application module

- Create application module XxNestedAM in JDeveloper. - Create a method printReqHeaderId in XxNestedAM to get instance ofPoRequisitionHeadersVO via root application module. Use getter method to print requisitionheader id in console.

package xxa2f.oracle.apps.icx.icatalog.shopping.server;import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;import oracle.apps.icx.icatalog.shopping.server.*;import oracle.apps.icx.por.req.server.*;import oracle.apps.fnd.framework.*;import oracle.apps.fnd.common.VersionInfo;

3 / 7

Page 4: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

public class XxNestedAMImpl extends OAApplicationModuleImpl { public XxNestedAMImpl() { }

public void printReqHeaderId() { System.out.println("Start > XxNestedAM.printReqHeaderId"); OAApplicationModule rootAM = (OAApplicationModule)getRootApplicationModule();

PoRequisitionHeadersVOImpl poh = (PoRequisitionHeadersVOImpl)rootAM.findViewObject("PoRequisitionHeadersVO"); PoRequisitionHeadersVORowImpl pohr = (PoRequisitionHeadersVORowImpl)poh.getCurrentRow(); System.out.println("POHeaderId=" + pohr.getRequisitionHeaderId()); System.out.println("End > XxNestedAM.printReqHeaderId"); }

public static final String RCS_ID = "$Header: XxNestedAMImpl.java 115.30 2009/05/1321:40:39 kryali noship $"; public static final boolean RCS_ID_RECORDED =VersionInfo.recordClassVersion("$Header: XxNestedAMImpl.java 115.30 2009/05/1321:40:39 kryali noship $", "xxa2f.oracle.apps.icx.icatalog.shopping.server");}

- Create extension NonCatalogRequestCO controller by naming it asxxNonCatalogRequestCO. In processFormRequest() method for AddToCart event, use createApplicationModule()to create instance of XxNestedAM and call method in nested application module using invokeMethod()method.

package xxa2f.oracle.apps.icx.icatalog.shopping.webui;

import oracle.apps.fnd.common.*;

4 / 7

Page 5: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

import oracle.apps.fnd.framework.*;import oracle.apps.fnd.framework.webui.*;import oracle.apps.fnd.framework.webui.beans.*;import oracle.apps.icx.por.req.webui.*;import oracle.jbo.ViewObject;import oracle.apps.icx.icatalog.shopping.webui.NonCatalogRequestCO;import oracle.apps.icx.icatalog.shopping.server.*;import oracle.apps.icx.por.req.server.*;import oracle.apps.fnd.common.VersionInfo;

public class xxNonCatalogRequestCO extends NonCatalogRequestCO { public xxNonCatalogRequestCO() { }

public void processFormRequest(OAPageContext oapagecontext, OAWebBeanoawebbean) { try { if(oapagecontext.getParameter("AddToCart") != null) { System.out.println("*** XX Custom Code Start ***"); OAApplicationModule ram =oapagecontext.getApplicationModule(oawebbean); // Create Nested Application Module OAApplicationModule nam =(OAApplicationModule)ram.findApplicationModule("XxNestedAM"); if (nam == null) nam = (OAApplicationModule)ram.createApplicationModule("XxNestedAM","xxa2f.oracle.apps.icx.icatalog.shopping.server.XxNestedAM"); nam.invokeMethod("printReqHeaderId");

System.out.println("*** XX Custom Code End ***"); } } catch (Exception e) { System.out.println("Error=" + e); }

super.processFormRequest(oapagecontext, oawebbean);

5 / 7

Page 6: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

}

public static final String RCS_ID = "$Header: xxNonCatalogRequestCO.java 115.302009/05/13 21:40:39 kryali noship $"; public static final boolean RCS_ID_RECORDED =VersionInfo.recordClassVersion("$Header: xxNonCatalogRequestCO.java 115.302009/05/13 21:40:39 kryali noship $", "xxa2f.oracle.apps.icx.icatalog.shopping.webui");}

I've used findApplicationModule() method to check if nested AM is alreadycreated, before creating another instance with the same name.

- Personalize NonCatalogRequestPG page to provide extendedController XxNonCatalogRequestCO as controller.

- Run NonCatalogRequestPG in JDeveloper. Enter details inNon-Catalog Request page and hit Add to Cart button. This printsrequisition header id in console output in JDeveloper.

This demonstrates how nested application module can be used to addcustom business logic in seeded OA Framework pages.

Any other approach?

6 / 7

Page 7: nested application modules

Nested Application Modules in OA Framework

Written by Kishore RyaliThursday, 14 May 2009 03:59

You can create a custom region say xxCustomRN with application module XxNestedAMand attach the region using OAF Personalization. So the application moduleXxNestedAM becomes nested to root application module via region. Thisinvolves more steps as you have to load custom region definition into MDSrepository using XMLImporterutility and create flexible layout to attach custom RN to seeded page. I'llcreate my next article on this topic.

Update: I've implemented alternate approach in the article How to extendroot AM using nested AM.I did not seem bad as I expected.

7 / 7