« The new WebLogic Developers Conference | Main | The New JDeveloper is Here »

Using selectOneChoice with JPA relationships

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.
bind.jpg

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:

bind.jpg

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

bind.jpg

Comments (2)

Pavle:

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

shay:

Pavle,

Seems like a bug in TP4 - this works perfectly fine in 10.1.3.3

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on July 15, 2008 1:32 PM.

The previous post in this blog was The new WebLogic Developers Conference.

The next post in this blog is The New JDeveloper is Here.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle