Sonntag, 27. März 2011

Building LOVs with popup search form and user defined search attributes

Using LOVs in ADF is both a blessing and a curse. On the one hand they are easy to use, on the other hand they can be very frustrating because of their ostensible mysterious behavior. In our specific case we ran into NullPointerException (ADF_FACES-60096) after migrating an application to a JDeveloper 11.1.1.4.0 project.

This blog post contains 2 parts. First we show how we implemented a LOV with a popup search region including user defined search attributes using a view critaria and bind variables. This approach has been working fine with JDeveloper 11.1.1.2.0 and also after migrating project to 11.1.1.3.0. The second part describes our workaround to get the LOV running within a JDeveloper 11.1.1.4.0 project.

Our sample bases upon Oracle's hr schema. It contains one Entity Object "EmployeesEO", a corresponding View Object "EmployeesVO" and a read-only View Object "LOVJobsVO" (SELECT * FROM jobs).    




A basic LOV with popup search dialog has already been configured in our previous LOV post.  
So we will use that sample application and extend it!

Our basic LOV sample works, but there is one disadvantage! Because of defining our search region bases upon "All Queryable Attributes" ...



... our LOV Search Region popup contains search fields for JobId, JobTitle, MinSalary and MaxSalary.



In our use case we only need to filter for attributes JobId and JobTitle, so our job is to remove the salary fields!


Part 1 - View Criteria and Bind Variables for user defined search attributes in LOV popup
To achieve that behavior, we have to create a view criteria on LOVJobsVO. To do this, edit LOVJobsVO, select section Query and add a new view criteria by clicking the related green plus symbol.




In Create View Criteria Dialog click Add Item. Set attribute to "JobId", operator to "contains" and operand to "Bind Variable". After that click the green plus next to field parameter to add a new bind variable




Configure the bind variable in the following way:



Create another bind variable JOB_TITLE for attribute JobTitle in the same way. Therefore select () Group in the LOVJobsVOCriteria-Tree before clicking button Add Item 






After creating the bind variables, our view criteria should be equal to that:



Now we are able to use the view criteria fields JobId and JobTitle as search fields in our LOV popup search form instead of "All Queryable Attributes". Therefore we edit the LOV in EmployeesVO...



... and choose the tab UI Hints of the upcoming dialog. The "Include Search Region" ComboBox contains a new entry "Use LOVJobsVOCriteria". We select that entry an close the edit dialog via OK button.



We are done!

Really? No!
As mentioned in the introduction, that approach was working until JDeveloper 11.1.1.3.0. When running it as a JDev 11.1.1.4.0 project it seems to run, but it does not!  When we run the application and click the magnifier symbol next to JobsLOV's input field everything seems to be fine. We are able to search for JobId and JobTitle:





That is the beavior we intended. So what's going wrong? When clicking a second time on the LOV's magnifier symbol a NullPointerException is thrown:



Part 2 - Workaround to avoid NullPointerException
We were able to fix the problem by substituting the bind variables from our view criteria with empty strings. For doing this edit the LOVJobsVO and mark the view criteria...


... After that select the source tab from the bottom of the overview page. We can see the XML-representation of our view criteria within the selected textblock.


Search for our view criteria items that contain bind variables :JOB_ID and :JOB_TITLE....



... and modify the attribute "IsBindVarValue" in both of the criteria items to "false". After that set the criteria items' "value" attributes  to "". The source code should now be equal to the following screenshot:



After modifying the source, don't forget to click "save all" icon.


Now, we are done!

If we run the application with the modified view criteria, we are able to use the LOV's popup search dialog more than one time!



Download extended sample application

1 Kommentar :