This week i will continue to enhance my previous post (Moving to Jdeveloper11g Your First ADF Form) and today i will cover how to create LOVs in Oracle ADF application.
Pre-requisites:
- HR Schema in Oracle database.
- Download this basic completed application and change the connection settings according to your environment.
Objective:
On this post we will create LOVs for Job, Department Id in Simple Employee based form.
Note: (Manager LOV is little tricky i will cover in next post)
Steps to follow:
For good naming convention we will rename the adf.demo.model.view package to queries
- Right click on adf.demo.model.view in Model project and choose Re-factor > Rename and rename it to adf.demo.mode.queries
Adding Departments and Jobs Entities:
Note: If you already have entities in your project then you can skip to next step
- Add Departments Entity by Right clicking on adf.demo.model.entities package in Model project and choose New Entity Object
Enter Name as "Departments" and Choose Schema object as "Departments" by pressing Browse button you can select from the list of objects as well.
- Choose All columns in attributes page and click Finish.
- Repeat the same step for Jobs entity.
Adding View Objects for Departments and Jobs LOVs :
- Right click on adf.demo.model.queries package and Choose New View Object.
- Enter name as "DepartmentsLOV" and other options as shown in the slide.
- Select the Departments Entity and Move to selected area uncheck the option Updatable.
- Select Department Name and Id Attributes to Selected area.
- Choose Departments Name in Order by section by pressing EDIT button you can select from List.
- Click Finish.
- Repeat same steps for Jobs Choose JobId and JobTitle as Attributes and JobTitle as Order by.
Creating LOVs:
- Double click EmployeeVO in adf.demo.model.queries section.
- Select DepartmentId attribute in the attribute page and Click "+" green button at the bottom under List of Values section.
- Click the green + button with List Data Source.
- Select DepartmentsLOV in Available Objects change the Name at the bottom to DepartmentsLOVAcesssor and Press > button to Create Accessor for LOV as shown in the slide click OK.
- Choose DepartmentId in List Attribute Return Values will populate automatically. Your Screen should similar to this.
- Go to UI Hints tab Leave the List type as Choice List (There are many type of LOVs available)
- Move Department Name from Available to Selected Area.
- Choose "Labeled Item(First of List)" at very bottom include "No Selection.." and set the Description as "
- Click OK
- Repeat Same Steps for JobId attribute.
Your EmployeeVO page should looks like this
Linking LOVs to JSF Page:
- Open employee.jspx page in View Controller Project
- Delete JobsId and DepartmentId attribute by selection them in Structure Window and Right click choose Delete.
- Refresh the DataControl page
- Expand the DataControl > EmployeeVO select DepartmentsId attribute and Drag and Drop it to FormLayout.
- Menu will appear select Single Selection > ADF One Choice List as shown in the slide
- Repeat the same step for JobId.
Your JSF Page should looks like this
- Right click and Choose Run
Your Page should looks like this on Runtime
Conclusion:
With Oracle ADF application development becoming fast easy and see how easy is to create LOVs in your ADF application as like in Oracle Forms.
Download:
You can Download my completed Application
Follow me on Twitter http://twitter.com/baigsorcl
Have a nice day,
Baig
Hello Baig,
ReplyDeleteYour application from http://www.4shared.com/file/240824660/357f1b02/MyFistJSF_Lovs.html has been removed.
Can you please upload it again.
Thanks a lot
Hi,
ReplyDeleteThis was very useful. I have two very basic questions as I am newbie to ADF.
1)why we need to include primary key while creating LOCAccessorview. Like we included DepartmentId when we require only department name. Also I tried to edit query by removing DepartmentId(primary key), but the LOV stopped Coming.
2)Is there a way I can retrieve distinct values in my lov. For example suppose if there are duplicate departments in above example, how can I get distinct departments in my LOV.
Thanks in advance for this.
Rohan Walia
Hi,
DeleteFor LOV you need 2 column one to provide unique identifier and other as display column. If you don't have unique identifier and your display column is unique then you can create LOV over it.
If you don't have any unique column then it will be difficult for you to maintain your data.
Hope it helps,
ZB
Hi,
ReplyDeleteCan I have multiple return values? I mean, for example, I have a table which has 3 columns say A,B,C. I have LOV for A column. When I select a value from LOV, other column values should get filled automatically. Is it possible to do?
Yes you need to write Return listener on the LOV check this blog http://andrejusb.blogspot.com/2007/12/complex-list-of-values-lov-in-oracle.html
DeleteZ
Thank You.
ReplyDelete