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.
Like this:

And that's it. Run the page and it will look like this:

Comments (2)
Hi!
In TP4, with this example, I was not able to update the manager. SelectOneChoice is populated as expected (with dpts manager selected as expected). But if I change the manager, only Id is changed in employee entity of manager while all other attributes remain the same. So, when I call merge(department) EJB Session method to update department with newly selected manager, nothing happens. So, I think that you example is good for selecting the Id of new manager, but the session facade method must "know" to fetch a employee entity using messed-up managers entity (new Id with all other attributes preserved from old manager) provided in department. This is very error prone, as this behavior is not consistent with EJB mapping philosophy.
I think that the ADFm should enable native support for mapping the entire entity object (department-manager) instead to be limited to ADF BCs (and database table) attribute (id) mapping philosophy.
Regards,
Pavle
Posted by Pavle | July 20, 2008 4:35 AM
Posted on July 20, 2008 04:35
Pavle,
Seems like a bug in TP4 - this works perfectly fine in 10.1.3.3
Posted by shay | July 25, 2008 8:33 AM
Posted on July 25, 2008 08:33