If you use ADF Business Components for building your business services, ViewCriteria defined on your ViewObject act as the model for the af:query component. af:query component (backed up with ViewCriteria) is smart enough to address most of the common use cases declaratively. However there may be some use case scenarios, where developers need to go beyond the declarative development approach and dirty their hands a bit:) One such scenario is displaying search form prameters, conditionally. In other words, parameters in the query panel needs to be displayed based on certain conditions. Let me try explaining a possible solution for this use case. Please remember that each query parameter displayed in af:query is modeled by a ViewCrieteriaIteminstance. Apparently, you can make use of the ViewCriteriaItemHints to control the display properties. Following piece of code may help you to hide the ViewCriteriaItem programmatically.
viewCrieteriaItem.setProperty(
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE,
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_NEVER);
Hey, hang on, I’m not finished!From Fusion Developer's Guide:
If you are changing the value of a view criteria item programmatically, you must invoke the ViewCriteria.saveState() method to prevent the searchRegion binding from resetting the value of the view criteria item to the value that was specified at design time.
So you may need to call ViewCriteria.saveState() to persist the changes.
viewCrieteriaItem.setProperty(
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE,
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_NEVER);
viewCriteria.saveState();
That’s it...now sit back and relax!You can download the sample workspace from here. This example illustrates the above mentioned use case -i.e.: hiding search form parameters at runtime. This sample has two pages department.jspx and employee.jspx. User can navigate from department page to employee search page. The employee.jspx is hosting a task flow that in turn contains a query panel + result table. Department Id displayed inside the query panel of the employee page will be hidden from the user if he/she navigates from department page after selecting a specific department (which makes sense too).
[Runs with Oracle JDeveloper 11g R1 PS1 + HR Schema]