22 Nov 2015

Dynamic View Criteria UI Hints

In this post I am going to show how we can manipulate view criteria UI hints (such as Show in List, Search Region Mode, Show Operators,  etc.) dynamically on-the-fly. Let's consider a use case when we need to show or hide a view criteria in the drop down list of af:query component depending on user permissions.

Actually, it's very easy. We have to override ViewObjectImpl method getViewCriteria(String name) like this:

@Override
public ViewCriteria getViewCriteria(String name)
{
  ViewCriteria vc = super.getViewCriteria(name);
  if (isCriteriaPermitted(name))
  {
    vc.setProperty(ViewCriteriaHints.CRITERIA_SHOW_IN_LIST,
                   ViewCriteriaHints.CRITERIA_HINT_TRUE);     
  }
  else
  {
    vc.setProperty(ViewCriteriaHints.CRITERIA_SHOW_IN_LIST,
                   ViewCriteriaHints.CRITERIA_HINT_FALSE);
  }
  return vc;
}

isCriteriaPermitted in this code snippet is a custom method returning whether the view criteria is available for the user on af:query component. The getViewCriteria method can be overridden in your base ViewObjectImpl class in order to provide a generic solution for this use case across the application.

That's it! 


No comments:

Post a Comment

Post Comment