Thursday, October 25, 2012

Primary Key Importance for LOV View Object

Keep in mind, if you want to enable ADF Faces LOV component for autocompletion - you must have primary key defined for LOV View Object (even this View Object is readonly). Otherwise, ADF Faces LOV component may not function properly - new value will not be accepted and reverted back to original one.

I will demonstrate such behavior in this sample app - LOVPrimaryKeyApp.zip.

Originally, LOV VO didn't had any primary key defined - we will test how it works:


LOV VO is defined for JobId attribute:


ADF UI is set with AutoSubmit=True property for LOV component:


LOV field originally is loaded with AD_VP value:


We change it to be IT_PROG and tab out:


From the log we can see ADF executes two SQL statements - first it filters by IT_PROG and then suddenly it executes same SQL but without bind variable - its where new value is lost and LOV is reset back to original value AD_VP:


This happens because ADF tries to validate new value and execute findByKey method for that reason. However, if there are no key defined on LOV VO - it fails to execute findByKey and performs blind SQL execution without any bind variables at all. Value is reset back to original - AD_VP:


Let's set primary key for LOV VO - JobId:

 Finally now findByKey is executed correctly, because LOV VO contains key attribute. New value was validated correctly and accepted - see second SQL:


There is still a big mystery why ADF executes two SQL statements to validate new value for LOV. We would need to dig into ADF source code to understand that.

5 comments:

Anonymous said...

Can you please help in how to set this Auto Complete feature. I tried the steps explained in this demo like setting autosubmit to true. But the value is not getting populated when I tab out.
What i am trying to do is the autoComplete feature like what we have in Oracle forms

Anonymous said...

I see that when I tab out the value is getting populated. But can we get the value in the input box before we tab out. Because usually when an end user types a value, he will not press tab after typing 2 letters of the word unless he know the value will be auto-completed it. But can we have something like when the user types itself the value gets populated in the field

Andrej Baranovskij said...

Yes - you should try to use ADF Auto Suggest behavior. You can Google for it...

Andrejus

Anonymous said...

Thanks for the feed back. But I would like to elaborate more on my question.
Say I have an PetName field. And in my DB I have row values Cat, Dog, Parrot, Birds etc. So if I start typing 'C' in the PetName field, before I complete typing, 'Cat' should be populated in the field. I am not looking for an auto suggest behaviour where the values get listed down below the field. Instead the value should be populated in the field. This feature is there in Oracle forms as told to me by my colleague, and the same has to be implemented in ADF as they are planning to migrate the same.

Andrej Baranovskij said...

ADF LOV component doesnt work like that, user needs to tab out. If you want without tabbing out - custom component needs to be implemented.

In general - Oracle Forms users cant expect all the things working exactly the same, its different technology.

Andrejus