Showing posts with label Bind Parameters. Show all posts
Showing posts with label Bind Parameters. Show all posts

Saturday, 9 June 2012

View Object Bind Parameter pitfall

Well one get to a point in ADF development when it has been a long time since you've referenced the ADF Documentation and so I got to this pitfall with regards to Bind Parameters on View Objects. In my specific scenario I wanted to use Bind Parameters with wildcard values such as nulls amongst others. Hence, I discovered out of my ignorance that Bind Parameters get excluded when they have null values, unless they are marked as required parameters. After hours of debugging and struggle to get things working, everything started working suddenly after making all bind parameters required.

One of my colleagues also discovered another rule (as documented) with regards to view objects and bind parameters, but I'll provide those hints at another time...

Here it is:
Bind parameters marked as required can only be used in your main VO query. Those not marked as required can only be used in your View Criteria.
Thanks to Anilin Reddy!!

Thursday, 28 July 2011

ADF Tree : Setting Bind Parameters on a hierarchy of View Objects in your backing bean code

I was faced with the scenario of a hierarchical View Object defined in a View Link in order to make use of it in an ADF Tree component. The re-used/recursive View Object has bind parameters which are required and have to be set.

It was easy enough to get to the "parent" View Object in the hierarchy by using the Iterator binding as in the code sniplet below:

// get reference to the parent view object via the iterator binding
DCIteratorBinding iter = ADFUtils.findIterator("IteratorName");
ViewObject parentVO = iter.getViewObject();

// set bind parameter value on parent view object
parentVO.ensureVariableManager().setVariableValue("BindParameterName",      "BindParameterValue");

However, the "child" View Object in the hierarchy remained without its bind parameters set. Eventually, I got to the following solution (PLEASE NOTE: You have to use the destination view object accessor name as it is defined in the View Link you've created):

// get reference to the child view object via the parent view object binding
ViewObject childVO = ADFUtils.getChildViewObjectFromParent(parentVO, "ChildVOAccessorName");

// set bind parameter value on child view oibject
childVO.ensureVariableManager().setVariableValue("BindParameterName", "BindParameterValue");

The ADFUtils utility methods used above were implemented as follow:

public static DCIteratorBinding findIterator(String name) {
    DCIteratorBinding iter = getDCBindingContainer().findIteratorBinding(name);
    if(iter == null) {
      throw new RuntimeException("Iterator '" + name + "' not found");
    }
    return iter;
}

public static ViewObject getChildViewObjectFromParent(ViewObject parentVO, String childAccessorName) {
    AttributeDef attrDef = parentVO.findAttributeDef(childAccessorName);
    if(attrDef == null) {
      throw new RuntimeException("Attribute Definition '" + childAccessorName + "' not found on parent view object");
    }   
    return attrDef.getAccessorVO(parentVO);
}