Monday, August 16, 2010

ADF 11g: toggle operators in query component

When you use view criteria to be exposed in an <af:query/> component, it is sometimes weird that ADF allows you to change query operators. In this use case I define a view criteria using a BETWEEN clause on two dates.



When you create an <af:query/> component based on this criteria, you will see that it is rendered with operation 'between' as the selected operator. You do however have the possibility to change the operators. This actually makes no sense because you only need between.



You can change this behavior on the UI-hints tab of the view criteria editor.



When you run the application again, no operators are shown, but you can still insert two dates, still making it clear to the user that the search will be from - to.



This is a design-time solution. You can also manipulate this at run-time.

Run-time manipulation

For this you need to create the view object implementation class. In this class you then create a method that will show or hide the operators. By setting the "displayOperators" property of the view criteria, you can toggle between the show "InAdvancedMode" and show "never" mode.
1:   public void toggleShowOperators(){  
2: for (ViewCriteria vc:getAllViewCriterias()){
3: System.out.println(vc.getName());
4: System.out.println("displayOperators before change " + vc.getProperties().get("displayOperators"));
5: if (vc.getProperties().get("displayOperators")=="InAdvancedMode"){
6: vc.setProperty("displayOperators", "never");
7: }else
8: {
9: vc.setProperty("displayOperators", "InAdvancedMode");
10: }
11: System.out.println("displayOperators after change " + vc.getProperties().get("displayOperators"));
12: }
13: }


You publish this method to the client and drop it as an <af:commandToolbarButton/> on your page. Last thing is to set partialSubmit attribute of the button and the partialtriggers attribute of the corresponding <af:query/> component.

1:  <af:toolbar id="t1">  
2: <af:commandToolbarButton text="toggleShowOperators"
3: id="ctb1"
4: actionListener="#{bindings.toggleShowOperators.execute}"
5: disabled="#{!bindings.toggleShowOperators.enabled}"
6: partialSubmit="true"
7: />
8: </af:toolbar>
9: <af:panelHeader text="Employees" id="ph1">
10: <af:query id="qryId1" headerText="Search" disclosed="true"
11: value="#{bindings.EmployeesHireDateCriteriaQuery.queryDescriptor}"
12: model="#{bindings.EmployeesHireDateCriteriaQuery.queryModel}"
13: queryListener="#{bindings.EmployeesHireDateCriteriaQuery.processQuery}"
14: modeChangeVisible="false"
15: queryOperationListener="#{bindings.EmployeesHireDateCriteriaQuery.processQueryOperation}"
16: resultComponentId="::resId1"
17: partialTriggers="::ctb1"/>
18: </af:panelHeader>


Now you can toggle between the show operators by pushing the button.

Thursday, August 12, 2010

ADF 11g: Change attribute order in query component

Ever wondered if you can change the order in which the attributes are displayed in an 'af:query' component? It can be done. Here is how.

After you have created BC you can drop the named criteria "all queriable attributes" as an 'af:query' component with table.



When you run this, you will see the default generated query component. let's assume that the attributes in this component are not in the order that you like. You are in desperate need to show the "job" attribute first.



The solution is at view object level. You can change the order of the attributes by invoking the "Set Source Order" button. This button will show you a popup in which you can reorder the attributes. Use the button(s) so the attributes are in the order you want.



If you run the page again, the query component shows the "job" attribute first.



Too bad that this is a design time solution. There are some pending ER's regarding this subject.

Monday, August 09, 2010

ADF 11g: Using a List in Query component

When you create a default query component you might miss some of the features that ADF offers to you. One of these is the use of lists in the query component. In this post I'll explain to you how to do that.

First image here is the way a query component displays when you use all the defaults, and do no tweaking at all. Forget that I already changed some attributes so they are not displayed in the query component.

It looks ok, but the user of your application might not be so happy. They have to know the id of all departments. This is fine when you only have a few, but what if you have many ?

Let's try to add a list to the query component.

We have to start with the creation of the lookup item for department name. This can also be used in the actual table showing the results. First we add an entity usage for departments to the employees view object

After this we can add the lookup items.

Now create the list of values. The list of values should be based on the departments name attribute.

On the second tab set the UI hints for the list of values. Be aware of the fact that you can only use a couple of list types that can be used in the query component. For now we pick the combo box with list of values.

The last step in the process is to set the queriable property of the departmentId's (both base and lookup) to false.

When you run the page now, you will see that the contains a nice list with all departments.

You can even invoke a complete List Of Values, when you select 'search...' in the combobox (green area in picture above).


Much better than working with department id's (see the difference with the first picture in this post).