Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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:

faces-config.xml



JSP:


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!