jQuery in Action, 3rd edition
The moose likes JSF and the fly likes h:selectOneMenu - setting the correct value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "h:selectOneMenu - setting the correct value" Watch "h:selectOneMenu - setting the correct value" New topic

h:selectOneMenu - setting the correct value

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
Hi guys! I'm trying to poppulate an h:selectOneMenu byu calling this method

in my JSP, I call it like this...

Now, assignedTo is actually an Employee class attached to another class through composition.

And ofcourse, I have the getters and setters

The Employee class looks like this...

However, on the selectOneMenu tag, the value field is the Objects' toString output.

I need the value to be the int value returned by the getEmployeeId returned by the employee class like this:

How can I do this? Is there something wrong in what I'm doing? Thanks!

SCJP 1.5
Daniel Rhoades
Ranch Hand

Joined: Jun 30, 2004
Posts: 186
Create a custom converter for your Employee class then register it against the select item list:



Your converter class implements javax.faces.convert.Converter which has two methods:

In getAsString just cast "value" as "Employee" return employeeId from the object.

In getAsObject assume "newValue" is the employeeId and look it up in the database/persistence mechanism or however you want.

Using a converter in this way will get the Employee into assignEmployee.

Change the way you create select items to get the Employee name:

[ May 16, 2007: Message edited by: Daniel Rhoades ]

Drinking more tea is the key...
I agree. Here's the link: http://aspose.com/file-tools
subject: h:selectOneMenu - setting the correct value
It's not a secret anymore!