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:
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: