File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes selectOneListbox and converters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneListbox and converters" Watch "selectOneListbox and converters" New topic

selectOneListbox and converters

Juan Med�n

Joined: Sep 22, 2003
Posts: 4

Based on the documentation, you must write a converter for each custom object you wish to show in a selectOneListBox. This means that if you have a simple business object as:

public class Country {
private int _code;
private String _name;

// Getters and setters

You can't just create a list of SelectItem's to feed it. Ex.:

Country testCountry = new Country("Germany", 100);
SelectItem si1 = new SelectItem(testCountry, testCountry.getName());

and then a setter in your backing bean like:

public void setCountry(Country c) { /* code */ }

It seems to me that JSF should handle the conversion, since it has all the info it needs to do it. Otherwise, it'd mean that, for a model with 100+ business objects, you should write 100+ converters.

I'm sure I'm missing something. Do you know if is it possible to use the selectOneListBox this way ? Any comment would be really welcome.

Best regards,

- Juan
I agree. Here's the link:
subject: selectOneListbox and converters
It's not a secret anymore!