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. :-)

No comments:

Post a Comment