Using selectOneChoice with JPA relationships
By Shay Shmeltzer-Oracle on Jul 15, 2008
On OTN some asked how to create a selectOneChoice item from an object that relates to another object when using JPA and ADF Faces.
Here is the quick how-to.
We'll use the default Employees and Departments table from the HR schema. Just create default JPA entities on them with the JDev wizard and then create a service facade and right click it to create a data control.
First you'll drag the Departments object from the queryDepartmentsFindAll DC onto a JSF page and drop as an ADF Form.
Now you want to show the name of the manager of each department in a drop down list.
To do this expand the Employees object underneath the departments and click the firstName.
Drag it over to the JSF page and drop as a selectOneChoice component.
You'll be prompted to bind the list. You want to bind it to a list of employees - so you'll create a new List data source based on the queryEmployeesFindAll
You'll map the EmployeeID and you can choose to display the first name.
And that's it. Run the page and it will look like this: