Expanding on Bit #26 - Overriding getAttributeDef() to conditionally set an attribute property, you can set a View Object's attribute queryable property simply by calling setQueriable() on its ViewAttributeDefImpl. As explained in Bit #26, you can get the AttributeDef attribute definition by calling getAttributeDef() and passing the attribute index as a parameter. In order to call any of the attribute set...() methods, you will have to cast the AttributeDef interface to an ViewAttributeDefImpl implementation. By the way, did you know that by setting an attribute's queryable property will show or hide a View Criteria Item (i.e. the criterion) based on the attribute on the af:query dialog? Another way to hide the criterion was outlined in Bit #25 - Hiding a View Criteria item based on some condition. It will also show or hide the attribute from the Add Fields drop-down in the Advanced mode of af:query. One last thing: check-out the plethora of set...() methods available in the ViewAttributeDefImpl. As you may have guessed it, pretty much everything that is available declaratively on the Edit Attribute dialog, can be set (or reset) dynamically in your code based on some business condition. For a complete use case, check out the reference listed below.
Example:
/**
* Helper to set an attribute's queriable property.
* Example:
* setQueriable(ViewRowImpl.SOMEFIELDINDEX, something.equals(somethingElse));
*
* @param attribIndex the attribute index
* @param condition the condition (true/false)
*/
protected void setQueriable(int attribIndex, boolean condition) {
// set the attribute queryable as needed
AttributeDef def = super.getAttributeDef(attribIndex);
boolean queryable = condition;
// set/reset queriable only if needed
if (def != null && def.isQueriable() != queryable) {
ViewAttributeDefImpl attributeDef = (ViewAttributeDefImpl)def;
attributeDef.setQueriable(queryable);
}
}
Context:
View Object Implementation Class
References:
http://dstas.blogspot.com/2010/03/set-queryable-property-on-attribute.html
No comments:
Post a Comment