Friday, July 1, 2011

Overriding <af:query> display at run time

Sometime back I posted similar post on the above topic - Customizing the af:query component display by overriding CriteriaItemAttributeHints

Its time for me to revisit the same topic with slightly different use case :)
The use case requirement was to override the ViewCrtieria hints of a base view object from a child view object. Well, its easy. You can hook your code by overriding ViewObjectImpl::getCriteriaItemAttributeHints(ViewCriteriaItem vci), and optionally return your own AttributeHints implementation. In the following code sample, I'm demonstrating this by changing some properties of a ViewCriteriaItem for specific items.

 /**  
  * By default return null. Subclasses may override to return  
  * custom AttributeHints implementation for the given criteria item.  
  */  
 @Override  
 public AttributeHints getCriteriaItemAttributeHints(ViewCriteriaItem vci) {  
   if (vci != null && vci.getViewCriteria().getName().equals("EmployeesViewCriteria")) {  
     if (vci.getAttributeDef().getName().equals("FirstName")) {  
       vci.setRequired(ViewCriteriaItem.VCITEM_OPTIONAL);  
     } else if (vci.getAttributeDef().getName().equals("DepartmentId")) {  
       vci.setProperty(ViewCriteriaItem.RENDERED_MODE, ViewCriteriaItem.CRITERIA_RENDERED_MODE_NEVER);  
     }  
   }  
   return super.getCriteriaItemAttributeHints(vci);  
 }  

Before winding up today's post, let me teach you one more useful tip on the same context. An interesting enhancement available with 11.1.2.0.0 release is the ability specify 'Display Width' for each view criteria item while defining a view criteria. This property decides the width of the UI control (displayed inside the query component) at run time. Please note that in previous releases the af:query component was using display width from the view object's attribute definition (by default) to render controls.


Download

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

A glance at the implementation

This sample uses 2 view object
1. A base view object - EmployeesView
2. A child view object extended from EmployeesView - EmpDeptView. Child view object inherits 'EmployeesViewCriteria' defined on base view object.

The EmpDeptViewImpl overrides certain properties of 'EmployeesViewCriteria' from the base view object by using getCriteriaItemAttributeHints(...) method. Take a look at the below shown scree shot to understand this example better. The screen shot displays two query components one from EmployeesView and the other from EmpDeptView. Though both query components are derived from same ViewCriteria defined on the base view object (EmployeesView), the second component displays slightly modified version by hiding the DepartmentId field and marking the FirstName as 'optional'. This is achieved by the altering ViewCriteriaItem instance in the getCriteriaItemAttributeHints(...) method.



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- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html

4 comments:

Anonymous said...

Hi Jobinesh,
Based on your post of Dynamic LOV, I am trying to create a radio group in a dynamic form component. I created a ListBinding and setting the AttributeHints of the column as

"AttrDef[itr].setProperty(AttributeHints.ATTRIBUTE_CTL_TYPE, AttributeHints.CTLTYPE_RADIOGRP);"

But still I am not getting the radio group displayed on the page. Am I missing something?

I am trying to create the following components dynamically in a dynamic form and was not able to

SelectOneRadio

SelectManyCheckbox

SelectManyChoice

SelectManyListbox

Can you please point me in some direction?

Thanks in advance

Anonymous said...

Hello,
you have mentioned a new feature since 11.1.2.0.0 (Display width of item in query component). I'm using currently the newest 11.1.2.3.0, but this feature doesn't work. All the items are stretched automaticly (according to database length i think). It doesn't work neither when i set up the Display width in Attributes/UI Hints. Do you have any experience with this? thanks

Tony Caravana Campos said...

Hello,

Same error of anonymous:

"You have mentioned a new feature since 11.1.2.0.0 (Display width of item in query component). I'm using currently the newest 11.1.2.3.0, but this feature doesn't work. All the items are stretched automatically (according to database length i think). It doesn't work neither when i set up the Display width in Attributes/UI Hints. Do you have any experience with this?"

Have any idea of how to solve it?

Thanks

Jobinesh said...

Well, I had a look at it. Look like the way this property has been defined in VO xml has been changed between builds and it's not being migrated when you open an 11.1.2.2.0 application in 11.1.2.3.0 release of JDev. A work around is given here:
1. Open the application in 11.1.2.3.0
2. Open the VO. Then open the VC in the VC editor. Got to UI Hints tab, select Criteria item and set the Display Width
3. After step2, Got to source tab of VO, and select the VC and then manually remove the previously defined(which is added added when you set UI hints for VC Item using 11.1.2.2.0 ver) SchemaBasedProperties and its child tags for the VC Item .

If you have many such instances and above step is not a feasible option for you, please file a Bug through Oracle Service Request.