I completely agree, Johan. Bad example - I really like John Krasney's
example - a lot more elegant:


public MyBusinessClass {
  private int period; // getter/setter omitted for clarity }

MyBusinessClass myObject = // blah
List periods = Arrays.asList(new Integer[] { 1, 7, 14, 30, 365 });

new DropDownChoice("period",
  new PropertyModel(myObject, "period"),
  periods,
  new ChoiceRenderer() {
    public String getDisplayValue(Object object) {
      int period = ((Integer) object).intValue();
      switch (period) {
        case 1: return "Day";
        case 7: return "Week";
        case 14: return "Fortnight";
        case 30: return "Month";
        case 365: return "Year";
        default: throw new RuntimeException();
      }
    }
  }
);

-----Original Message-----
From: Johan Compagner [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 09, 2008 10:43 PM
To: [email protected]
Subject: Re: DropDownChoice throws IllegalArgumentException with Integer
values

And thats why i think the wiki example is a bad one. It points people
in the wrong way.

On 5/10/08, John Krasnay <[EMAIL PROTECTED]> wrote:
> On Fri, May 09, 2008 at 06:42:11PM -0700, Michael Mehrle wrote:
>> Thanks for the input, John - but I the plot thickens here. It seems
that
>> there is actually a Wicket bug that needs to get fixed. After a lot
of
>> tinkering I figured out why I was getting this error. The VERY FIRST
>> TIME my renderer is being called it actually calls getIdValue() with
an
>> Integer, not with the Object that I'm using. In my debugger I saw the
>
> This isn't a bug. The integer is coming from your business model.
> DropDownChoice calls getIdValue() with this value so it can pre-select
> the correct option based on your current business object value.
>
> I'll try explaining this again. Maybe this time it will click.
>
> You give a DDC a model and a list of possible values. The type of
object
> returned by the model and the type of objects in the list *must* be
the
> same. You've already mentioned that your model returns an Integer, so
> you *must* pass a list of Integers, not IntegerSelectChoice or
anything
> else.
>
> If you want to display something different than the integer, you have
to
> implement some custom code in ChoiceRenderer.getDisplayValue(). Don't
> get hung up on the idea that the value returned has to be a property
of
> the objects in your list. It can be anything, such as the
> getString("period_" + object.toString()) in my example.
>
> You are probably used to a Model2 framework like Struts, where you
have
> to create lists of key/value pair objects to render <select>s. No need
> for such an artificial structure in Wicket.
>
> Is the light coming on yet?
>
> jk
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to