• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:selectOneMenu - setting the correct value

 
Timothy Sam
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!
 
Daniel Rhoades
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic