Showing posts with label RichTree. Show all posts
Showing posts with label RichTree. Show all posts

Friday, 28 October 2011

ADF : Dynamically disabling Command Link component as contained in Rich Tree node stamp

I decided to use a RichCommandLink component as part of my RichTree(Menu) node stamp in order to produce actions to navigate in the application. Later on the requirement came that some sections of the system should be viewable and hence even the link to these sections should be disabled in order to prevent users from going there in the first place. Of course, the question remains why the menu was not configured correctly in the first place, because why show the tree node if it's going to be disabled anyway...but that's besides the point for this post. :-P

Well to dynamically disable the command links as contained in the tree, I've followed the following approach:
  • Set a JSP/JSTL core variable equal to some property in the node binding on which you can base the check for the view privilege. In my case I used a variable called: "mapParameter", with its value as a concatenated string containing the node's view name.
<c:set var="mapParameter" value="isViewable:#{node.ViewName}" />
  • Then, I used the above parameter in the EL Expression as value for the disabled property of the command link. You'll notice I've made the backing bean (called: menuBean) implement the Map interface in order to check for view privileges with the view name as parameter.
<af:commandLink text="#{node.Name}" id="cl1" action="someAction"
          disabled="#{((menuBean.hasPrivilege[mapParameter] == 'false') ? true : false)}"/>


I know Maps are probably not the best way in making things happen in backing beans, but I've managed to do all sorts of weird and wonderful things by using the Map method. :-)

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);
}