Friday, December 27, 2013

ADF Dynamic ADF BC - Surviving Passivation/Activation Events

ADF dynamic ADF BC and dynamic ADF UI implementation is useful functionality and is required almost in every larger project. Primary area where this functionality is applied - report parameters screens, instead of building hundreds of static report parameter screens for every report, we can build one dynamic and regenerate required ADF BC objects structure, together with dynamic ADF UI. Here you can read my previous post for the same topic - ADF Generator for Dynamic ADF BC and ADF UI - Recreate. Today post provides improved sample application with added support for ADF dynamic functionality working in passivation/activation event scenario.

Download updated sample application - Previous sample application contained one dummy VO - DynamicView:

This VO was replaced on runtime with real dynamic VO, created programmatically in HrModule class. This didn't worked in stress test environment, simulated by disabling AM pooling:

Null pointer exception for ADF dynamic form - activation event was failing:

It was failing, because on activation, ADF runtime was trying to activate original dummy VO - not the one we have substituted programmatically:

In theory it should work to remove dummy VO and change it with programmatic one, but really it fails on activation event:

Solution is pretty simple for this - we can get rid of dummy VO completely and rely directly on VO instance created programmatically on runtime. There is no need to define dummy VO in AM Data Model:

There is no need to have dummy VO either:

As there is no dummy VO anymore, no need to remove it's instance. We can simply create new programmatic VO instance with given name:

In page definition we should reference VO instance by the same name, obviously it will be highlighted as design time error - as there is no such VO instance defined statically, but this will work on runtime:

There are few additional improvements to survive passivation/activation events better - I will list them all below:

1. Non editable primary key - you should add primary key attribute and hide it to be non editable

2. If there is no default value for the attribute, it can be marked as not selected in query and there will be no need to include it into SQL statement

3. Not specifically related to passivation/activation - but for dependent LOV's, we need to set AutoSubmit=true for the parent attribute:

Dependent attribute should be set with backward dependency, this will reset attribute value automatically, when parent attribute value is changed:

4. SQL statement includes only selected attributes, where default value is set:

5. Dynamic VO doesn't passivate and activate correctly by default. We need to passivate and activate such VO manually. Standard method for passivation should be overridden, we can read current row attribute values and passivate them:

Standard method for activation should be overridden, to activate and set values to the current row attributes back:

6. If there are LOV's created dynamically, all such LOV's must be assigned with primary key:

Here you can see how it works on UI. Let's select Location Id, based on selected value LOV for Department Id is filtered and returns 50:

If you change Location Id, Department Id will be cleared automatically and user could select new Department Id value corresponding to the currently selected Location Id:


vinay20 said...

Great and useful post....

giovanni said...

Hi Andrejus,
i need ask you how add, for example in a dynamic lov, the valueChangeListener event dynamically.

Thank you for your useful posts


Andrej Baranovskij said...

This would be more complex to achieve with ADF dynamic form. In more complex screens, I usually generate dynamic UI with forEach, so I have control for each component.


longfly said...

I also want to ask if I want to create radio component for page,how do I define the third addViewAttribute() parameter? Or if I want to use checkbox component to display more options,is it possible? thanks a lot.

Andrej Baranovskij said...

Checkbox works fine for me in this sample. May be i will add radio support in the next blog for this topic.


Anonymous said...


Many thanks for all your blog articles! I'm facing the same issue in 12c but for non dynamic view Any ideas on that problem?



Anonymous said...

Hi Andrejuss,

I encounter weird behavior. I have a dynamic vo based on a simple select statement that fetches department id and deparment name (query: select DEPARTMENT_ID, DEPARTMENT_NAME FROM DEPARTMENTS). Department Id is the primary and mandatory key. I am testing with AM pooling off.

Now to the weird part: I have added a button to the page which simply calls a request-scoped bean method which doesn't do anything; it's there just to make a server request. Whenever I click this button, the value of dept id is copied into the dept name column. When I check the value of the dept name attribute in the button action listener, it returns the dept id value for the dept name attribute. Also, when I used value change listener, there also the new value for the department name field has the department id value. All this without my changing anything on the page. Any insights?