Friday, March 1, 2013

Default Dynamic Value for ADF Query Search Field

What if you face requirement, which tells to give default value for ADF query field in the search box. This is not just for some static value, but default search parameter must come from another LOV view object. As example in this post, I will implement use case where first value from LOV view object will be set as default value for the search field.

Download sample application - First thing you would consider is to uncheck "Include No Selection Item" for LOV configuration. This works for regular LOV's, but not for those ones included into ADF query search:

See - DepartmentId choice list is rendered without any default value assigned (we would assume, first value should be set by default):

With a bit of coding, we can make it work. Let's include Groovy code expression and reference custom method from VO implementation for Bind Variable default value:

When Bind Variable is assigned with default value, this allows to show this value in the LOV search field included into ADF query.

Default value is calculated dynamically - custom method is responsible for this action. Method gets instance of LOV VO from Application Module, retrieves first row and returns value for LOV key attribute. Make sure to use VO first() method and don't use executeQuery(). Groovy expression for Bind Variable value calls custom method multiple times, executeQuery() would invoke SQL each time when method is called. first() method works differently, it will retrieve already fetched row from cache:

Don't forget to register LOV VO instance in Application Module, otherwise custom method will fail to find it. This instance will be used to retrieve default value for LOV rendered in ADF query search block.

Here we can see how it looks on runtime, default value is set for the choice list automatically:

User can change choice list value and search:

If reset operation is invoked for ADF query - default value is set back again:


Unknown said...

Hi Andrejus,

I do really need this implementation, putting a default selected value in the selectOneChoice in AF query component.

But the problem is, the steps here are not applicable to JDev 11g Release 1(

When I put the groovy expression as you told as default value for bind variable, it isn't accepted, causing error.

Any work around on this?

Thank you so much for your helps.

I am your fan!



Sangati said...

Hi Andrejus.

I also have to do similar implementation but I want to default and attribute from and attribute from another vo.

I am not sure how shall I do that as I am very new to ADF.

Can you pls help

Sangati said...

Hi Andrejus,
I am very new to ADF. I want to default a second raw of a vo into a transient attribute of another vo as groovy. How can I achieve that
Pls help

Unknown said...

Hi Andrejus,

Good day.

With the release of ADF, is there a feature on AF Query Panel that handles the read-only feature of a certain text field/input text or List of Values (Select OneChoice). This is not supported yet in older version,

Thanks in Advance,

Jaime Jr

NS said...

Hi Andrejus,
This implimentation works when we need to show the default value for LOV. But when I try to select a different value from the LOV, only the default value is getting saved as the attribute value, no matter what other values I choose.. This Should not be expected right? Can you please advise what am I doing wrong?


Andrej Baranovskij said...

This post about ADF Query, we don't save value in ADF Query, but use it for search.


Richard Burk said...


I have been performing much trial and error with no success. My situation is as follows.
1. I have a search form (af:query) using a custom named criteria defined with multiple LOVs. For simplicity just assume one LOV for this custom named criteria.
2. The LOV is defined as an SQL Query View with two fields, code and description.
3. I wish to display the code and the description in the search form. However I wish to keep them in sync with each other so if code is changed, then description is changed automatically and vice versa.
4. I also have the operators available so it is possible for the user to choose various operators. The intention of this search form is to be specific. It will disallow pattern matching by limiting the available operators to just those that take a specific value??? if possible.
5. How do I keep the two values in sync with each other and ensure that they are displaying in sync information immediately after the search button has completed the query?

Anonymous said...

Hi Andrejus,
If I use date field as dropdown, in this scenario search table is populating with first row of the LOV but dropdown is not defaulting to LOV. if I remove LOV from Date field then it is setting to query panel date field

Can you please let me know hoe to achieve same requirement for date as dropdown?

Kumar Gaurav said...

Hi Andrejus,,
I am having a use case where I am using 'Input List of Values' component for providing option to choose from a list of values. My data control is giving me the values 'WWD','PPO','SDO','UXP'...etc. During the runtime, the 'Input List of Values' component is showing first value 'WWD' in the textbox with option(search icon) to choose other values. My requirement is to display blank value(empty) the text field and when user clicks on search icon, the popup box should allow user to choose from that list. Please suggest the needful.

Kishore said...

Hi Sir,
I have an scenario to set default value for Query based lov here I am sharing my scenario please give your valuable suggestions.

There is a dropdown it will display all years based on some id, the query is written below


by executing the above query it will display 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 years.
I drag and drop the queryvo as drop down in jsff page.

(Here I am facing an issue like) when I select 2016 year data is autopopulate from XYZ_CITIZC table,
and i click on save button it is stored in ABC_VARINC_YEAR TABLE
Next time when I login in I want to show the last user selected year(2016) in the drop down but I am geeting 2009 year by default. How solve this issue