• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

h:selectOneMenu - setting the correct value  RSS feed

Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!