Saturday, May 29, 2010

Use Case: View Criteria Conditionally Query-able Attribute

Today I will talk about specific use case - how to reuse the same ADF Task Flow with View Criteria for different scenarios. Generally, it is quite clear how to do this, however I will point on several tips and tricks. Hopefully, it will help you to implement stable design easier and with less effort.

Download sample application - ViewCriteriaConditionalQueryAttr.zip. Central part of this application is Employees ADF Task Flow:


It contains Router activity, two Method Calls and region. Based on task flow parameter value, router navigates to specific Method Call, where View Criteria is reset and applied. If task flow input parameter is not null, Employees are filtered by Department:


I should mention, that View Criteria contains hidden criteria item to filter by DepartmentId - this item is set to be rendered never:


Render Mode = Never is used for DepartmentId item, because the same View Criteria is implemented as Query component on the page and also I'm using it programmatically to filter by DepartmentId attribute. However, I don't want to render criteria item, I'm using for programmatic filtering.

Let's assume, Use Case is implemented and we are testing it. Default dynamic region for Locations is loaded:


I'm using menu, to navigate and open Employees dynamic region. Once its opened, I switch Query component to Advanced mode and expand Add Fields list. I can see DepartmentId attribute in the list, which is correct - it is valid to filter employees by department in this case:


Let's go back to Locations region, and select any of available locations:


Press Departments button, to open Locations summary screen, with all corresponding departments listed below. We select one of the departments and press Employees button:


At that time, Employees ADF Task Flow is opened with Department parameter value. Router activity navigates and filters employees by department - Query component block is conditionally disclosed:


Repeat the same steps, and open Add Fields list for Employees criteria being in Advanced mode. You will see DepartmentId attribute available in the list. This is incorrect from the user point of view. We want to see employees only from selected department, it will be invalid to search by DepartmentId in this case:


If user really wants to search by DepartmentId, he should open Employees region from the main menu. How we can prevent this and guarantee correct funcationality? Answer is simple - using conditionally queryable attribute. You already saw Method Calls in Employees ADF Task Flow, lets take a bit closer look. Both Method Calls have return values, return value is used to enable conditional expression for Query component Disclosed property:


Both Method Calls are invoking custom methods from Application Module Implementation class:


Here are those methods, key part of today Use Case:


First method is filtering Employees by DepartmentId, second is resetting View Criteria to initial state. View Criteria is reset, auto execution mode is set, bind variable initialized and finally View Criteria is applied. There is one more very important thing - changeAttributeQueryable(String, Boolean) method. This method makes DepartmentId attribute queryable or not - depending from where it is invoked. If we reset View Criteria and enter in default mode - attribute is queryable, otherwise its not. Method that controls attribute queryable property is implemented in Employees View Object Implementation class:


To enable/disable queryable property programmatically, we simply can use setQueriable(Boolean) method from ViewAttributeDefImpl:


We are testing again, and opening filtered Employees region by selected Department:


DepartmentId attribute is not available in Add Fields list anymore, its what we need:


If Employees region is opened now directly from the main menu:


DepartmentId will be present now in Add Fields list. Thats correct, because View Criteria was reset and we can search employees by any department:

3 comments:

  1. Hi Andrejus,
    I find property "Queriable" is in application level. I mean if I set the "Queriable" of departmentId to false, "Queriable" of departmentId in all VO instances will be false. Scenario: A opens the page that departmentId should be in the "Add Fields" list. Then B opens the page that departmentId should NOT be in the "Add Fields" list. Now A click "Advanced" button, an error will pop up.

    ReplyDelete
  2. Hi John,
    I've tested the scenario that you explain (with a second user in an other browser) and I haven't found this problem (no error) ...
    Are you sure for your remark ?
    Thanks (and Thanks too to Andrejus for this excellent explanation !),

    ReplyDelete
  3. Thank you Andrejus. Excellent article.

    ReplyDelete