Skip to main content

Long living Dynamic Business Components

Recently I came across an interesting post from Juan Oropeza (Oracle) in an internal wiki, the code was illustrating dynamic ViewObject creation which lives beyond user sessions. Thanks to Steve Muench who did help me to understand this thing better. Today's post is on this topic.

What is so great about this concept? Well, there are few good stuff for you. Read on...

In one of my previous post, I blogged about building dynamic UI -Model driven approach for building Dynamic UI. There the life of a dynamically created view object or entity object were limited to a user session in which they were created. What if you need the dynamically created ADF business components to be available across all user, beyond a specific user session. A real life use case may be adding couple of more attributes or validations on an existing View Object definition at run time which needs be reflected across all users. Well this is quite possible by getting the personalization definition of the ViewObject - PDefViewObject and performing the alteration on it. Later, When an meta data for view object or entity definition is loaded, it checks for corresponding PDef object and, if present, superimpose the PDef on existing meta data. The end-user sees a definition that is the union of the base definition plus the additional personalizations. The below shown code snippet may help you to understand the API to be used for altering view object which needs to live beyond the user session. Please note that pDefVO.saveXMLContents() makes use of MDS to store the altered definition. To make this thing to work, you may need to have right entries added in your adf-config.xml.

 private boolean addLocAttributeToDeptView() {  
      ViewDefImpl viewDef = ViewDefImpl.findDefObject("sessiondef.dynamic.DynamicDeptViewDef");  
      PDefViewObject pDefVO = (PDefViewObject)viewDef.getPersDef();  
      if (pDefVO == null) {  
           pDefVO = new PDefViewObject();  
      if (pDefVO.getAttributeIndexOf(ATTRIB_LOC_ID) != -1) {  
           return false;  
      pDefVO.addEntityAttribute(ATTRIB_LOC_ID, "DynamicDeptUsage", ATTRIB_LOC_ID, true);  
      return true;  


You can download the sample workspace from here.
[Runs with Oracle JDeveloper (11g R2) + HR Schema]

A glance at the implementation

This example uses personalizedbc-sample-task-flow-definition to create a dynamic entity object and view Object. The second step in the task flow alter the dynamic view object to add location id right before displaying the dynamically created VO to end user.

The adf-config.xml used for this example has been configured to use file based MDS store to keep the dynamic business component definitions.
           <namespace path="/sessiondef" metadata-store-usage="mdsRepos"/>  
           <namespace path="/persdef" metadata-store-usage="mdsRepos"/>  
           <namespace path="/xliffBundles" metadata-store-usage="mdsRepos"/>  
           <metadata-store-usage id="mdsRepos" deploy-target="true" default-cust-store="true"/>  
           <!-- <property name="metadata-path" value="/tmp"/> -->  

How to run this sample?

1. Run main.jspx
2. This sample is security enabled. Key in user name/password as developer1/developer1, when asked for.
3. The above mentioned task flow generates DynamicDeptEntityDef and DynamicDeptViewDef at runtime and saves the definition to MDS store. The DynamicDeptVO1 is exposed to client for use.
4. Run the main.jsf once again and this time enter username/password as developer2/developer2. You may notice that previously created VO definition is available to the second user as well.

Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post-


N said…
Hi Jobinesh,

What does the oracle.jbo.server.EntityDefImpl.DEF_SCOPE_SESSION indicates in the below code EntityDefImpl entDef =
new EntityDefImpl(oracle.jbo.server.EntityDefImpl.DEF_SCOPE_SESSION, "DynamicDeptEntityDef");. Thanks.
Shobith U said…
Hi Jobinesh,

When i am trying to test the method buildDynamicDeptComp in the AMImpl class i am getting MDSConfiguration exception as below namespace "/sessiondef" mapped to metadata-store-usage "mdsRepos" but its definition was not found in MDS configuration.
Pls read this post
Vamsi Krishna said…
Hi Jobinesh,

I am getting a 'NameClashException: JBO-25001: Object COURSE_ID of type Attribute already exists' exception while trying to append one more attribute to existing PDef.(as below)

PDefViewObject pDefVO = PDefViewObject)viewDef.getPersDef();

pDefVO.addEntityAttribute(attrName, "DynamicDeptUsage1",attrName, true);

and the same exception is reoccurring while removing attributes from PDef.

Could you please help me in this regard.

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…