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 - ADFQueryDefaultValueApp.zip. 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:

6 comments:

Jaime Jr Jacinto 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(11.1.1.6.0).

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!

Regards,

Jaime

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

Jaime Jr Jacinto said...

Hi Andrejus,

Good day.

With the release of ADF 11.1.1.7.0, 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, 11.1.1.6.0

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?

Thanks
Nazia

Andrejus Baranovskis said...

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

Andrejus