webtier@glassfish.java.net

Re: [webtier] h:selectOneMenu with complex type for value

From: Martin Beránek <martin.beranek_at_i.cz>
Date: Tue, 02 Mar 2010 06:50:55 +0100

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:
>
> &lt;h:selectOneMenu value="#{foo.color}"&gt;
> &lt;f:selectItems value="#{foo.colors}"/&gt;
> &lt;/h:selectOneMenu&gt;
>
> 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:
>
> &lt;h:selectOneMenu value="#{foo.count}"&gt;
> &lt;f:selectItems value="#{foo.counts}"/&gt;
> &lt;/h:selectOneMenu&gt;
>
> 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