X

Shay Shmeltzer's Oracle Development Tools Tips

Using selectOneChoice with JPA relationships

Shay Shmeltzer
Director of Product Management - Oracle

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

Join the discussion

Comments ( 4 )
  • Pavle Sunday, July 20, 2008
    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 Friday, July 25, 2008
    Pavle,
    Seems like a bug in TP4 - this works perfectly fine in 10.1.3.3
  • vha Monday, December 1, 2008
    Hi All
    Your form is edit form , If this form is create new then selectOneChoise is not work , it disabled .
    Why ?
    thank for help
  • Nelson Tuesday, February 10, 2009
    Shay,
    I tried to use this mechanism to render a selectOneChoice field on my Toplink Essentials based project. But there was a bad effect if the "employees" attribute is null (because the DB allows it, in our model), the selectOneChoice simply dissapear.
    The work around for this issue is to use an accessor for the "firsName" attribute on the Departments entity in order to use it as a binding for the selectOneChoice.
    Hope this help somebody somewhere :)
    Thanks for this article.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.