• 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

h:selectOneMenu - setting the correct value

 
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 ]
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic