I find it very interesting that it worked with Integer, but not with Color.
Could that come down to auto boxing? I was seeing a similar problem to
yours using a selectManyListBox and had to write a custom converter. My
case was slightly different in that with a selectMany I was setting a
collection instead of a single value, so I attributed mine to type erasure
in generics. I was expecting a List<Key> but was getting a List<String>.
If you want more info on my case you can read about it at
http://digitaljoel.wordpress.com/2010/01/11/jsf-2-custom-converter/
Fortunately,
converters (just like everything else) are even easier in JSF 2.
In any case I'd love to hear from the experts.
Joel
2010/3/1 Martin Beránek <martin.beranek_at_i.cz>
> I'am not sure, but I thing that you need converter for type Color. You can
> register one globaly... (as in Jsf 1.x)
>
> Martin
>
> Dne 2.3.2010 03:25, webtier_at_javadesktop.org napsal(a):
>
> I want to do this:
>>
>> <h:selectOneMenu value="#{foo.color}">
>> <f:selectItems value="#{foo.colors}"/>
>> </h:selectOneMenu>
>>
>> The getColor and setColor methods return/take a Color object, where Color
>> is a simple class I made up to test this. The getColors method returns a
>> SelectItem[]. I tried making the SelectItem[] two different ways:
>>
>> 1) SelectItem[] colors = { new SelectItem(new Color(...)), ... };
>> In this case, I gave Color a toString method that spits out a color name
>> like "red".
>>
>> 2) SelectItem[] colors = { new SelectItem(new Color(...), "red"), ... };
>>
>> In both cases, it properly displays the color names ("red", "green", etc.)
>> in the menu. But, in both cases, when I try to submit the form, I get
>>
>> Conversion Error setting value 'myPackage.Color_at_6c2a78' for 'null
>> Converter'.
>>
>> I [u]can[/u] get this general process to work if I use Integer as the
>> type. Ie, something like this works fine:
>>
>> <h:selectOneMenu value="#{foo.count}">
>> <f:selectItems value="#{foo.counts}"/>
>> </h:selectOneMenu>
>>
>> Here, getCount and setCount get/take an Integer, and getCounts returns a
>> SelectItem[] containing entries like
>>
>> new SelectItem(1, "One")
>>
>> I don't think the behavior has changed since JSF 1.x, so I think the
>> problem is that I never understood how to do this in the first place. I was
>> under the impression that this process should be straightforward without
>> defining any converters; I thought that all I had to do was to make the type
>> of the value of h:selectOneMenu match the Object type (first constructor
>> argument) of each SelectItem. What am I doing wrong?
>>
>> Cheers-
>>
>> - Marty
>> [Message sent by forum member 'martyhall' (hall_at_coreservlets.com)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=389538
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>>
>>
> --
> Martin Beránek
> mailto:martin.beranek_at_i.cz
> http://www.i.cz
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>