You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael Mehrle <mi...@ask.com> on 2008/05/09 02:18:50 UTC

DropDownChoice throws IllegalArgumentException with Integer values

This is the error I'm getting:

 

[DEBUG LoadAdDataInterceptor] Loaded
AdData:com.evite.common.ad.model.AdData@17ceb9b 

[ERROR RequestCycle] Cannot format given Object as a Number 

java.lang.IllegalArgumentException: Cannot format given Object as a
Number

            at java.text.DecimalFormat.format(DecimalFormat.java:480)

            at java.text.Format.format(Format.java:133)

            at
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
tToString(AbstractNumberConverter.java:109)

            at
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
solverConverter.java:84)

 

I'm using List<SelectOption> to populate the DropDownChoice, as per the
online example:

 

http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
ml

 

The only change I made to SelectOption is to set the 'value' field to an
Integer (which I need for my model).

 

Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
the label/value pairs as the labels show up properly.

 

Thanks,

 

Michael


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, May 09, 2008 at 09:15:50AM -0700, Michael Mehrle wrote:
> Great input and you're forgiven for jumping the gun with SelectOption
> ;-)
> 
> I didn't even know there was a wicket SelectOption, which puts a new
> spin on things. Regarding the conversion back to the model: Yes, I was
> following the example hoping IT WOULD BE CORRECT.
> 
> I concur with you that it's probably trying to cast SelectOption into an
> Integer, but that doesn't explain why it actually works when I refrain
> from tagging a non-integer string to the label (e.g. '1' as the label
> vs. '1 guest'). How does it manage to convert properly then?
> 
> Michael

Well, it's probably noticing that it's a string and trying
Integer.parseInt(), but it's really beside the point. Unless you follow
the "golden rule" your code will most certainly break in 1.4, where the
DDC constructor looks something like this:

public DropDownChoice(String id, Model<T> model, List<T> choices,
ChoiceRenderer<T> choiceRenderer);

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Great input and you're forgiven for jumping the gun with SelectOption
;-)

I didn't even know there was a wicket SelectOption, which puts a new
spin on things. Regarding the conversion back to the model: Yes, I was
following the example hoping IT WOULD BE CORRECT.

I concur with you that it's probably trying to cast SelectOption into an
Integer, but that doesn't explain why it actually works when I refrain
from tagging a non-integer string to the label (e.g. '1' as the label
vs. '1 guest'). How does it manage to convert properly then?

Michael

-----Original Message-----
From: John Krasnay [mailto:john@krasnay.ca] 
Sent: Friday, May 09, 2008 9:02 AM
To: users@wicket.apache.org
Subject: Re: DropDownChoice throws IllegalArgumentException with Integer
values

On Fri, May 09, 2008 at 11:53:30AM -0400, John Krasnay wrote:
> On Fri, May 09, 2008 at 08:25:05AM -0700, Michael Mehrle wrote:
> > Anyone? Was hoping for some input here ;-)
> > 
> >
http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
> > ml
> > 
> > The only change I made to SelectOption is to set the 'value' field
to an
> > Integer (which I need for my model).
> > 
> 
> That example is terrible. SelectOption is a Wicket component and an
> internal implementation detail of DropDownChoice. It should not be in
> your business model as the example shows.
> 
> If you're setting an integer property via a DropDownChoice, you should
> pass a List<Integer> and implement ChoiceRenderer.getDisplayValue() to
> output the right string to display.
> 
> My wild-ass guess would be that Wicket is trying to cast a
SelectOption
> into an Integer, with predictable results.
> 
> jk

Ugh, I just noticed that the example has its own SelectOption class, not
the one from Wicket. But I stand by the "golden rule" of DropDownChoice:
always pass a list of the same type of object that you expect to receive
back in your business model.

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, May 09, 2008 at 11:53:30AM -0400, John Krasnay wrote:
> On Fri, May 09, 2008 at 08:25:05AM -0700, Michael Mehrle wrote:
> > Anyone? Was hoping for some input here ;-)
> > 
> > http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
> > ml
> > 
> > The only change I made to SelectOption is to set the 'value' field to an
> > Integer (which I need for my model).
> > 
> 
> That example is terrible. SelectOption is a Wicket component and an
> internal implementation detail of DropDownChoice. It should not be in
> your business model as the example shows.
> 
> If you're setting an integer property via a DropDownChoice, you should
> pass a List<Integer> and implement ChoiceRenderer.getDisplayValue() to
> output the right string to display.
> 
> My wild-ass guess would be that Wicket is trying to cast a SelectOption
> into an Integer, with predictable results.
> 
> jk

Ugh, I just noticed that the example has its own SelectOption class, not
the one from Wicket. But I stand by the "golden rule" of DropDownChoice:
always pass a list of the same type of object that you expect to receive
back in your business model.

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, May 09, 2008 at 08:25:05AM -0700, Michael Mehrle wrote:
> Anyone? Was hoping for some input here ;-)
> 
> http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
> ml
> 
> The only change I made to SelectOption is to set the 'value' field to an
> Integer (which I need for my model).
> 

That example is terrible. SelectOption is a Wicket component and an
internal implementation detail of DropDownChoice. It should not be in
your business model as the example shows.

If you're setting an integer property via a DropDownChoice, you should
pass a List<Integer> and implement ChoiceRenderer.getDisplayValue() to
output the right string to display.

My wild-ass guess would be that Wicket is trying to cast a SelectOption
into an Integer, with predictable results.

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Any ideas that work with 1.3.3? ;-)

-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 9:30 AM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


I posted on my wiki how I solved this problem.  Hopefully it will help
you:

http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example

-Doug



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Hey Doug - thanks for the update - good to hear that it works on 1.3.3.
Bummer having to remove the generics - you did a great job defining the
generic types. Reading the code makes my head spin!! :-)

I'll do some surgery on this and hope to get it working.

Cheers,

Michael

-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 2:23 PM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


Yes, I'm on 1.4-m1.  However, you can remove all the generic stuff and
it
will still work.  I just migrated to generics yesterday, so the code
does
work on 1.3.3.

Or you can invest in moving to 1.4-m1.  It seems to be working great and
using generics is nice.

-Doug


Michael Mehrle wrote:
> 
> Hi Doug:
> 
> Thanks for that - this might just work :-) One problem I'm running
into
> is that the version of IChoiceRenderer I am using cannot be
> parameterized (it's not generic). Do you have a different wicket
release
> than I do?
> 
> I'm on 1.3.3.
> 
> Michael
> 
> -----Original Message-----
> From: Doug Donohoe [mailto:doug@donohoe.info] 
> Sent: Friday, May 09, 2008 9:30 AM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with
Integer
> values
> 
> 
> I posted on my wiki how I solved this problem.  Hopefully it will help
> you:
> 
>
http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example
> 
> -Doug
> 
> 
> Michael Mehrle wrote:
>> 
>> The code is pretty massive, would be tough to post all that here.
>> Basically, it's an integer backed DropDownChoice that has the word
>> 'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
>> When I remove the word 'guest' in the label it works just fine. Did
> your
>> dropdown have integers as the labels or was there more?
>> 
>> It seems that the problem lies in the conversion, and that Wicket
>> somehow is trying to grab the label value and put it into the model.
>> 
>> If anyone has run into such a problem I'd appreciate any input.
>> 
>> Michael
>> 
>> 
>> 
>> -----Original Message-----
>> From: Doug Donohoe [mailto:doug@donohoe.info] 
>> Sent: Friday, May 09, 2008 8:41 AM
>> To: users@wicket.apache.org
>> Subject: RE: DropDownChoice throws IllegalArgumentException with
> Integer
>> values
>> 
>> 
>> Post your code.  It's hard to guess w/out seeing the code.  I have an
>> integer-based drop down choice working well (I used that example as
my
>> starting point).
>> 
>> -Doug
>> 
>> 
>> Michael Mehrle wrote:
>>> 
>>> Anyone? Was hoping for some input here ;-)
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 6:35 PM
>>> To: users@wicket.apache.org
>>> Subject: RE: DropDownChoice throws IllegalArgumentException with
>> Integer
>>> values
>>> 
>>> Okay, I just stepped through this and getting the feeling that
>> 'somehow'
>>> the label is being passed on to the model. Now, if the label is '1'
> it
>>> works fine, but if it's '1 day', then I get that error.
>>> 
>>> The question here is: why is the label being passed back to the
> model?
>>> Doesn't make any sense - I'm using a ChoiceRenderer as such:
>>> 
>>> new ChoiceRenderer("label", "value")
>>> 
>>> Do I also need to add some kind of converter to properly assign the
>>> model?
>>> 
>>> Any input would be appreciated.
>>> 
>>> Michael
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 5:19 PM
>>> To: users@wicket.apache.org
>>> Subject: DropDownChoice throws IllegalArgumentException with Integer
>>> values
>>> 
>>> This is the error I'm getting:
>>> 
>>>  
>>> 
>>> [DEBUG LoadAdDataInterceptor] Loaded
>>> AdData:com.evite.common.ad.model.AdData@17ceb9b 
>>> 
>>> [ERROR RequestCycle] Cannot format given Object as a Number 
>>> 
>>> java.lang.IllegalArgumentException: Cannot format given Object as a
>>> Number
>>> 
>>>             at
java.text.DecimalFormat.format(DecimalFormat.java:480)
>>> 
>>>             at java.text.Format.format(Format.java:133)
>>> 
>>>             at
>>>
>>
>
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
>>> tToString(AbstractNumberConverter.java:109)
>>> 
>>>             at
>>>
>>
>
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
>>> solverConverter.java:84)
>>> 
>>>  
>>> 
>>> I'm using List<SelectOption> to populate the DropDownChoice, as per
>> the
>>> online example:
>>> 
>>>  
>>> 
>>>
>>
>
http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
>>> ml
>>> 
>>>  
>>> 
>>> The only change I made to SelectOption is to set the 'value' field
to
>> an
>>> Integer (which I need for my model).
>>> 
>>>  
>>> 
>>> Anyone any ideas as to what's going on? I'm pretty sure I didn't
swap
>>> the label/value pairs as the labels show up properly.
>>> 
>>>  
>>> 
>>> Thanks,
>>> 
>>>  
>>> 
>>> Michael
>>> 
>>> 
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>>
>
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
>> h-Integer-values-tp17139227p17150771.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
> h-Integer-values-tp17139227p17151647.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
h-Integer-values-tp17139227p17156630.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
I used some of your stuff but ran into a suspected 1.3.3 Wicket bug (see
previous message I just sent out).

Thanks for the help - go and enjoy your weekend.

Michael

-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 6:41 PM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


You can get at the underlying Integer by calling getKey() on the
IntegerSelectChoice object the model holds.  If that doesn't work,
you'll
have to figure out an alternative on your own.  The good news is that
you
have working code to start from.

-Doug



Michael Mehrle wrote:
> 
> I like your solution, but you are using an IntegerSelectChoice as your
> model, which won't work for me. I need to set my model to a regular
> Integer since that's what's being persisted on the backend.
> 
> Michael
> 

-- 
View this message in context:
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
h-Integer-values-tp17139227p17159082.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Doug Donohoe <do...@donohoe.info>.
You can get at the underlying Integer by calling getKey() on the
IntegerSelectChoice object the model holds.  If that doesn't work, you'll
have to figure out an alternative on your own.  The good news is that you
have working code to start from.

-Doug



Michael Mehrle wrote:
> 
> I like your solution, but you are using an IntegerSelectChoice as your
> model, which won't work for me. I need to set my model to a regular
> Integer since that's what's being persisted on the backend.
> 
> Michael
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-with-Integer-values-tp17139227p17159082.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
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:jcompagner@gmail.com] 
Sent: Friday, May 09, 2008 10:43 PM
To: users@wicket.apache.org
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 <jo...@krasnay.ca> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Johan Compagner <jc...@gmail.com>.
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 <jo...@krasnay.ca> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Yeah, I can be thick headed at times ;-)

Actually the solution is to add some custom code to getIdValue(), not
getDisplayValue(). It's a bit of a hack, but seems to work fine now.
Next time I'll build this differently though, that's for sure.

Thank you for walking me through this. This whole thing was a bit
confusing to me, especially since that tutorial leads people in the
wrong direction. It makes complete sense that the model and list objects
need to be of the same type.

Best,

Michael

-----Original Message-----
From: John Krasnay [mailto:john@krasnay.ca] 
Sent: Friday, May 09, 2008 7:13 PM
To: users@wicket.apache.org
Subject: Re: DropDownChoice throws IllegalArgumentException with Integer
values

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by John Krasnay <jo...@krasnay.ca>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
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
same method being called with different object types (Integer and
IntegerSelectChoice). Take a look at my (obviously silly, but working)
work around:

/* Manages the display/id value for our dropdown choices. */
		private class CountChoiceRenderer implements
IChoiceRenderer {
			/**
			 * Get the display value from the SelectChoice
(what the user sees)
			 *
			 * @param object a SelectChoice object
			 * @return display
			 */
			@Todo(comment = "Replace Object with <T> once
Wicket incl. generics is available" )
			public String getDisplayValue(Object object) {
				return
((IntegerSelectChoice)object).getDisplay();
			}

			/**
			 * Get key value (what is returned from the
browser)
			 *
			 * @param object a SelectChoice object
			 * @param index not used
			 * @return object.getKeyAsString()
			 */
			@Todo(comment = "Replace Object with <T> once
Wicket incl. generics is available" )
			public String getIdValue(Object object, int
index) {
				String result = "A";
				if (object instanceof Integer) {
					// WICKET BUG!!!
					LOG.debug("Integer returned");
				} else {
					result =
((IntegerSelectChoice)object).getKeyAsString();
				}
				return result;
			}

		}

Now, it works, but only because I'm forcing my renderer to omit the case
when it's being called with an Integer. My log gets hit four times and
there are four dropdowns of that type in my panel. Very weird stuff
going on here. Of course there's a chance that I screwed something up,
but I have been over my code with a fine toothed comb and everything
looks clean. I'm only using IntegerSelectChoice for populating my
DropDownChoice, never Integers directly.

Michael

-----Original Message-----
From: John Krasnay [mailto:john@krasnay.ca] 
Sent: Friday, May 09, 2008 6:27 PM
To: users@wicket.apache.org
Subject: Re: DropDownChoice throws IllegalArgumentException with Integer
values

On Fri, May 09, 2008 at 03:39:07PM -0700, Michael Mehrle wrote:
> I like your solution, but you are using an IntegerSelectChoice as your
> model, which won't work for me. I need to set my model to a regular
> Integer since that's what's being persisted on the backend.
> 
> Michael

Quite right. I really don't like the idea of SelectChoice (a
view-related class) in a business model. Try this, Michael...

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();
      }
    }
  }
);

If like me you have to localize all your strings, it becomes even
simpler...

new DropDownChoice("period", 
  new PropertyModel(myObject, "period"),
  periods, 
  new ChoiceRenderer() {
    public String getDisplayValue(Object object) {
      return getString("period_" + object.toString());
    }
  }
);

...then in your properties file...

period_1=Day
period_7=Week
# ...and so on

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice throws IllegalArgumentException with Integer values

Posted by John Krasnay <jo...@krasnay.ca>.
On Fri, May 09, 2008 at 03:39:07PM -0700, Michael Mehrle wrote:
> I like your solution, but you are using an IntegerSelectChoice as your
> model, which won't work for me. I need to set my model to a regular
> Integer since that's what's being persisted on the backend.
> 
> Michael

Quite right. I really don't like the idea of SelectChoice (a
view-related class) in a business model. Try this, Michael...

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();
      }
    }
  }
);

If like me you have to localize all your strings, it becomes even
simpler...

new DropDownChoice("period", 
  new PropertyModel(myObject, "period"),
  periods, 
  new ChoiceRenderer() {
    public String getDisplayValue(Object object) {
      return getString("period_" + object.toString());
    }
  }
);

...then in your properties file...

period_1=Day
period_7=Week
# ...and so on

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
I like your solution, but you are using an IntegerSelectChoice as your
model, which won't work for me. I need to set my model to a regular
Integer since that's what's being persisted on the backend.

Michael


-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 2:23 PM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


Yes, I'm on 1.4-m1.  However, you can remove all the generic stuff and
it
will still work.  I just migrated to generics yesterday, so the code
does
work on 1.3.3.

Or you can invest in moving to 1.4-m1.  It seems to be working great and
using generics is nice.

-Doug


Michael Mehrle wrote:
> 
> Hi Doug:
> 
> Thanks for that - this might just work :-) One problem I'm running
into
> is that the version of IChoiceRenderer I am using cannot be
> parameterized (it's not generic). Do you have a different wicket
release
> than I do?
> 
> I'm on 1.3.3.
> 
> Michael
> 
> -----Original Message-----
> From: Doug Donohoe [mailto:doug@donohoe.info] 
> Sent: Friday, May 09, 2008 9:30 AM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with
Integer
> values
> 
> 
> I posted on my wiki how I solved this problem.  Hopefully it will help
> you:
> 
>
http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example
> 
> -Doug
> 
> 
> Michael Mehrle wrote:
>> 
>> The code is pretty massive, would be tough to post all that here.
>> Basically, it's an integer backed DropDownChoice that has the word
>> 'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
>> When I remove the word 'guest' in the label it works just fine. Did
> your
>> dropdown have integers as the labels or was there more?
>> 
>> It seems that the problem lies in the conversion, and that Wicket
>> somehow is trying to grab the label value and put it into the model.
>> 
>> If anyone has run into such a problem I'd appreciate any input.
>> 
>> Michael
>> 
>> 
>> 
>> -----Original Message-----
>> From: Doug Donohoe [mailto:doug@donohoe.info] 
>> Sent: Friday, May 09, 2008 8:41 AM
>> To: users@wicket.apache.org
>> Subject: RE: DropDownChoice throws IllegalArgumentException with
> Integer
>> values
>> 
>> 
>> Post your code.  It's hard to guess w/out seeing the code.  I have an
>> integer-based drop down choice working well (I used that example as
my
>> starting point).
>> 
>> -Doug
>> 
>> 
>> Michael Mehrle wrote:
>>> 
>>> Anyone? Was hoping for some input here ;-)
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 6:35 PM
>>> To: users@wicket.apache.org
>>> Subject: RE: DropDownChoice throws IllegalArgumentException with
>> Integer
>>> values
>>> 
>>> Okay, I just stepped through this and getting the feeling that
>> 'somehow'
>>> the label is being passed on to the model. Now, if the label is '1'
> it
>>> works fine, but if it's '1 day', then I get that error.
>>> 
>>> The question here is: why is the label being passed back to the
> model?
>>> Doesn't make any sense - I'm using a ChoiceRenderer as such:
>>> 
>>> new ChoiceRenderer("label", "value")
>>> 
>>> Do I also need to add some kind of converter to properly assign the
>>> model?
>>> 
>>> Any input would be appreciated.
>>> 
>>> Michael
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 5:19 PM
>>> To: users@wicket.apache.org
>>> Subject: DropDownChoice throws IllegalArgumentException with Integer
>>> values
>>> 
>>> This is the error I'm getting:
>>> 
>>>  
>>> 
>>> [DEBUG LoadAdDataInterceptor] Loaded
>>> AdData:com.evite.common.ad.model.AdData@17ceb9b 
>>> 
>>> [ERROR RequestCycle] Cannot format given Object as a Number 
>>> 
>>> java.lang.IllegalArgumentException: Cannot format given Object as a
>>> Number
>>> 
>>>             at
java.text.DecimalFormat.format(DecimalFormat.java:480)
>>> 
>>>             at java.text.Format.format(Format.java:133)
>>> 
>>>             at
>>>
>>
>
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
>>> tToString(AbstractNumberConverter.java:109)
>>> 
>>>             at
>>>
>>
>
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
>>> solverConverter.java:84)
>>> 
>>>  
>>> 
>>> I'm using List<SelectOption> to populate the DropDownChoice, as per
>> the
>>> online example:
>>> 
>>>  
>>> 
>>>
>>
>
http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
>>> ml
>>> 
>>>  
>>> 
>>> The only change I made to SelectOption is to set the 'value' field
to
>> an
>>> Integer (which I need for my model).
>>> 
>>>  
>>> 
>>> Anyone any ideas as to what's going on? I'm pretty sure I didn't
swap
>>> the label/value pairs as the labels show up properly.
>>> 
>>>  
>>> 
>>> Thanks,
>>> 
>>>  
>>> 
>>> Michael
>>> 
>>> 
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>>
>
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
>> h-Integer-values-tp17139227p17150771.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
> h-Integer-values-tp17139227p17151647.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
h-Integer-values-tp17139227p17156630.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Doug Donohoe <do...@donohoe.info>.
Yes, I'm on 1.4-m1.  However, you can remove all the generic stuff and it
will still work.  I just migrated to generics yesterday, so the code does
work on 1.3.3.

Or you can invest in moving to 1.4-m1.  It seems to be working great and
using generics is nice.

-Doug


Michael Mehrle wrote:
> 
> Hi Doug:
> 
> Thanks for that - this might just work :-) One problem I'm running into
> is that the version of IChoiceRenderer I am using cannot be
> parameterized (it's not generic). Do you have a different wicket release
> than I do?
> 
> I'm on 1.3.3.
> 
> Michael
> 
> -----Original Message-----
> From: Doug Donohoe [mailto:doug@donohoe.info] 
> Sent: Friday, May 09, 2008 9:30 AM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
> values
> 
> 
> I posted on my wiki how I solved this problem.  Hopefully it will help
> you:
> 
> http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example
> 
> -Doug
> 
> 
> Michael Mehrle wrote:
>> 
>> The code is pretty massive, would be tough to post all that here.
>> Basically, it's an integer backed DropDownChoice that has the word
>> 'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
>> When I remove the word 'guest' in the label it works just fine. Did
> your
>> dropdown have integers as the labels or was there more?
>> 
>> It seems that the problem lies in the conversion, and that Wicket
>> somehow is trying to grab the label value and put it into the model.
>> 
>> If anyone has run into such a problem I'd appreciate any input.
>> 
>> Michael
>> 
>> 
>> 
>> -----Original Message-----
>> From: Doug Donohoe [mailto:doug@donohoe.info] 
>> Sent: Friday, May 09, 2008 8:41 AM
>> To: users@wicket.apache.org
>> Subject: RE: DropDownChoice throws IllegalArgumentException with
> Integer
>> values
>> 
>> 
>> Post your code.  It's hard to guess w/out seeing the code.  I have an
>> integer-based drop down choice working well (I used that example as my
>> starting point).
>> 
>> -Doug
>> 
>> 
>> Michael Mehrle wrote:
>>> 
>>> Anyone? Was hoping for some input here ;-)
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 6:35 PM
>>> To: users@wicket.apache.org
>>> Subject: RE: DropDownChoice throws IllegalArgumentException with
>> Integer
>>> values
>>> 
>>> Okay, I just stepped through this and getting the feeling that
>> 'somehow'
>>> the label is being passed on to the model. Now, if the label is '1'
> it
>>> works fine, but if it's '1 day', then I get that error.
>>> 
>>> The question here is: why is the label being passed back to the
> model?
>>> Doesn't make any sense - I'm using a ChoiceRenderer as such:
>>> 
>>> new ChoiceRenderer("label", "value")
>>> 
>>> Do I also need to add some kind of converter to properly assign the
>>> model?
>>> 
>>> Any input would be appreciated.
>>> 
>>> Michael
>>> 
>>> -----Original Message-----
>>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>>> Sent: Thursday, May 08, 2008 5:19 PM
>>> To: users@wicket.apache.org
>>> Subject: DropDownChoice throws IllegalArgumentException with Integer
>>> values
>>> 
>>> This is the error I'm getting:
>>> 
>>>  
>>> 
>>> [DEBUG LoadAdDataInterceptor] Loaded
>>> AdData:com.evite.common.ad.model.AdData@17ceb9b 
>>> 
>>> [ERROR RequestCycle] Cannot format given Object as a Number 
>>> 
>>> java.lang.IllegalArgumentException: Cannot format given Object as a
>>> Number
>>> 
>>>             at java.text.DecimalFormat.format(DecimalFormat.java:480)
>>> 
>>>             at java.text.Format.format(Format.java:133)
>>> 
>>>             at
>>>
>>
> org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
>>> tToString(AbstractNumberConverter.java:109)
>>> 
>>>             at
>>>
>>
> org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
>>> solverConverter.java:84)
>>> 
>>>  
>>> 
>>> I'm using List<SelectOption> to populate the DropDownChoice, as per
>> the
>>> online example:
>>> 
>>>  
>>> 
>>>
>>
> http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
>>> ml
>>> 
>>>  
>>> 
>>> The only change I made to SelectOption is to set the 'value' field to
>> an
>>> Integer (which I need for my model).
>>> 
>>>  
>>> 
>>> Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
>>> the label/value pairs as the labels show up properly.
>>> 
>>>  
>>> 
>>> Thanks,
>>> 
>>>  
>>> 
>>> Michael
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
>> h-Integer-values-tp17139227p17150771.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
> h-Integer-values-tp17139227p17151647.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-with-Integer-values-tp17139227p17156630.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Hi Doug:

Thanks for that - this might just work :-) One problem I'm running into
is that the version of IChoiceRenderer I am using cannot be
parameterized (it's not generic). Do you have a different wicket release
than I do?

I'm on 1.3.3.

Michael

-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 9:30 AM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


I posted on my wiki how I solved this problem.  Hopefully it will help
you:

http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example

-Doug


Michael Mehrle wrote:
> 
> The code is pretty massive, would be tough to post all that here.
> Basically, it's an integer backed DropDownChoice that has the word
> 'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
> When I remove the word 'guest' in the label it works just fine. Did
your
> dropdown have integers as the labels or was there more?
> 
> It seems that the problem lies in the conversion, and that Wicket
> somehow is trying to grab the label value and put it into the model.
> 
> If anyone has run into such a problem I'd appreciate any input.
> 
> Michael
> 
> 
> 
> -----Original Message-----
> From: Doug Donohoe [mailto:doug@donohoe.info] 
> Sent: Friday, May 09, 2008 8:41 AM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with
Integer
> values
> 
> 
> Post your code.  It's hard to guess w/out seeing the code.  I have an
> integer-based drop down choice working well (I used that example as my
> starting point).
> 
> -Doug
> 
> 
> Michael Mehrle wrote:
>> 
>> Anyone? Was hoping for some input here ;-)
>> 
>> -----Original Message-----
>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>> Sent: Thursday, May 08, 2008 6:35 PM
>> To: users@wicket.apache.org
>> Subject: RE: DropDownChoice throws IllegalArgumentException with
> Integer
>> values
>> 
>> Okay, I just stepped through this and getting the feeling that
> 'somehow'
>> the label is being passed on to the model. Now, if the label is '1'
it
>> works fine, but if it's '1 day', then I get that error.
>> 
>> The question here is: why is the label being passed back to the
model?
>> Doesn't make any sense - I'm using a ChoiceRenderer as such:
>> 
>> new ChoiceRenderer("label", "value")
>> 
>> Do I also need to add some kind of converter to properly assign the
>> model?
>> 
>> Any input would be appreciated.
>> 
>> Michael
>> 
>> -----Original Message-----
>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>> Sent: Thursday, May 08, 2008 5:19 PM
>> To: users@wicket.apache.org
>> Subject: DropDownChoice throws IllegalArgumentException with Integer
>> values
>> 
>> This is the error I'm getting:
>> 
>>  
>> 
>> [DEBUG LoadAdDataInterceptor] Loaded
>> AdData:com.evite.common.ad.model.AdData@17ceb9b 
>> 
>> [ERROR RequestCycle] Cannot format given Object as a Number 
>> 
>> java.lang.IllegalArgumentException: Cannot format given Object as a
>> Number
>> 
>>             at java.text.DecimalFormat.format(DecimalFormat.java:480)
>> 
>>             at java.text.Format.format(Format.java:133)
>> 
>>             at
>>
>
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
>> tToString(AbstractNumberConverter.java:109)
>> 
>>             at
>>
>
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
>> solverConverter.java:84)
>> 
>>  
>> 
>> I'm using List<SelectOption> to populate the DropDownChoice, as per
> the
>> online example:
>> 
>>  
>> 
>>
>
http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
>> ml
>> 
>>  
>> 
>> The only change I made to SelectOption is to set the 'value' field to
> an
>> Integer (which I need for my model).
>> 
>>  
>> 
>> Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
>> the label/value pairs as the labels show up properly.
>> 
>>  
>> 
>> Thanks,
>> 
>>  
>> 
>> Michael
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
> h-Integer-values-tp17139227p17150771.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
h-Integer-values-tp17139227p17151647.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Doug Donohoe <do...@donohoe.info>.
I posted on my wiki how I solved this problem.  Hopefully it will help you:

http://wiki.donohoedigital.com/wiki/Wiki.jsp?page=DropDownChoice+Example

-Doug


Michael Mehrle wrote:
> 
> The code is pretty massive, would be tough to post all that here.
> Basically, it's an integer backed DropDownChoice that has the word
> 'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
> When I remove the word 'guest' in the label it works just fine. Did your
> dropdown have integers as the labels or was there more?
> 
> It seems that the problem lies in the conversion, and that Wicket
> somehow is trying to grab the label value and put it into the model.
> 
> If anyone has run into such a problem I'd appreciate any input.
> 
> Michael
> 
> 
> 
> -----Original Message-----
> From: Doug Donohoe [mailto:doug@donohoe.info] 
> Sent: Friday, May 09, 2008 8:41 AM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
> values
> 
> 
> Post your code.  It's hard to guess w/out seeing the code.  I have an
> integer-based drop down choice working well (I used that example as my
> starting point).
> 
> -Doug
> 
> 
> Michael Mehrle wrote:
>> 
>> Anyone? Was hoping for some input here ;-)
>> 
>> -----Original Message-----
>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>> Sent: Thursday, May 08, 2008 6:35 PM
>> To: users@wicket.apache.org
>> Subject: RE: DropDownChoice throws IllegalArgumentException with
> Integer
>> values
>> 
>> Okay, I just stepped through this and getting the feeling that
> 'somehow'
>> the label is being passed on to the model. Now, if the label is '1' it
>> works fine, but if it's '1 day', then I get that error.
>> 
>> The question here is: why is the label being passed back to the model?
>> Doesn't make any sense - I'm using a ChoiceRenderer as such:
>> 
>> new ChoiceRenderer("label", "value")
>> 
>> Do I also need to add some kind of converter to properly assign the
>> model?
>> 
>> Any input would be appreciated.
>> 
>> Michael
>> 
>> -----Original Message-----
>> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
>> Sent: Thursday, May 08, 2008 5:19 PM
>> To: users@wicket.apache.org
>> Subject: DropDownChoice throws IllegalArgumentException with Integer
>> values
>> 
>> This is the error I'm getting:
>> 
>>  
>> 
>> [DEBUG LoadAdDataInterceptor] Loaded
>> AdData:com.evite.common.ad.model.AdData@17ceb9b 
>> 
>> [ERROR RequestCycle] Cannot format given Object as a Number 
>> 
>> java.lang.IllegalArgumentException: Cannot format given Object as a
>> Number
>> 
>>             at java.text.DecimalFormat.format(DecimalFormat.java:480)
>> 
>>             at java.text.Format.format(Format.java:133)
>> 
>>             at
>>
> org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
>> tToString(AbstractNumberConverter.java:109)
>> 
>>             at
>>
> org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
>> solverConverter.java:84)
>> 
>>  
>> 
>> I'm using List<SelectOption> to populate the DropDownChoice, as per
> the
>> online example:
>> 
>>  
>> 
>>
> http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
>> ml
>> 
>>  
>> 
>> The only change I made to SelectOption is to set the 'value' field to
> an
>> Integer (which I need for my model).
>> 
>>  
>> 
>> Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
>> the label/value pairs as the labels show up properly.
>> 
>>  
>> 
>> Thanks,
>> 
>>  
>> 
>> Michael
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
> h-Integer-values-tp17139227p17150771.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-with-Integer-values-tp17139227p17151647.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
The code is pretty massive, would be tough to post all that here.
Basically, it's an integer backed DropDownChoice that has the word
'guest' tagged on to incrementing numbers (e.g. 1 - 10) in the label.
When I remove the word 'guest' in the label it works just fine. Did your
dropdown have integers as the labels or was there more?

It seems that the problem lies in the conversion, and that Wicket
somehow is trying to grab the label value and put it into the model.

If anyone has run into such a problem I'd appreciate any input.

Michael



-----Original Message-----
From: Doug Donohoe [mailto:doug@donohoe.info] 
Sent: Friday, May 09, 2008 8:41 AM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values


Post your code.  It's hard to guess w/out seeing the code.  I have an
integer-based drop down choice working well (I used that example as my
starting point).

-Doug


Michael Mehrle wrote:
> 
> Anyone? Was hoping for some input here ;-)
> 
> -----Original Message-----
> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
> Sent: Thursday, May 08, 2008 6:35 PM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with
Integer
> values
> 
> Okay, I just stepped through this and getting the feeling that
'somehow'
> the label is being passed on to the model. Now, if the label is '1' it
> works fine, but if it's '1 day', then I get that error.
> 
> The question here is: why is the label being passed back to the model?
> Doesn't make any sense - I'm using a ChoiceRenderer as such:
> 
> new ChoiceRenderer("label", "value")
> 
> Do I also need to add some kind of converter to properly assign the
> model?
> 
> Any input would be appreciated.
> 
> Michael
> 
> -----Original Message-----
> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
> Sent: Thursday, May 08, 2008 5:19 PM
> To: users@wicket.apache.org
> Subject: DropDownChoice throws IllegalArgumentException with Integer
> values
> 
> This is the error I'm getting:
> 
>  
> 
> [DEBUG LoadAdDataInterceptor] Loaded
> AdData:com.evite.common.ad.model.AdData@17ceb9b 
> 
> [ERROR RequestCycle] Cannot format given Object as a Number 
> 
> java.lang.IllegalArgumentException: Cannot format given Object as a
> Number
> 
>             at java.text.DecimalFormat.format(DecimalFormat.java:480)
> 
>             at java.text.Format.format(Format.java:133)
> 
>             at
>
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
> tToString(AbstractNumberConverter.java:109)
> 
>             at
>
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
> solverConverter.java:84)
> 
>  
> 
> I'm using List<SelectOption> to populate the DropDownChoice, as per
the
> online example:
> 
>  
> 
>
http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
> ml
> 
>  
> 
> The only change I made to SelectOption is to set the 'value' field to
an
> Integer (which I need for my model).
> 
>  
> 
> Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
> the label/value pairs as the labels show up properly.
> 
>  
> 
> Thanks,
> 
>  
> 
> Michael
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-wit
h-Integer-values-tp17139227p17150771.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Doug Donohoe <do...@donohoe.info>.
Post your code.  It's hard to guess w/out seeing the code.  I have an
integer-based drop down choice working well (I used that example as my
starting point).

-Doug


Michael Mehrle wrote:
> 
> Anyone? Was hoping for some input here ;-)
> 
> -----Original Message-----
> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
> Sent: Thursday, May 08, 2008 6:35 PM
> To: users@wicket.apache.org
> Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
> values
> 
> Okay, I just stepped through this and getting the feeling that 'somehow'
> the label is being passed on to the model. Now, if the label is '1' it
> works fine, but if it's '1 day', then I get that error.
> 
> The question here is: why is the label being passed back to the model?
> Doesn't make any sense - I'm using a ChoiceRenderer as such:
> 
> new ChoiceRenderer("label", "value")
> 
> Do I also need to add some kind of converter to properly assign the
> model?
> 
> Any input would be appreciated.
> 
> Michael
> 
> -----Original Message-----
> From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
> Sent: Thursday, May 08, 2008 5:19 PM
> To: users@wicket.apache.org
> Subject: DropDownChoice throws IllegalArgumentException with Integer
> values
> 
> This is the error I'm getting:
> 
>  
> 
> [DEBUG LoadAdDataInterceptor] Loaded
> AdData:com.evite.common.ad.model.AdData@17ceb9b 
> 
> [ERROR RequestCycle] Cannot format given Object as a Number 
> 
> java.lang.IllegalArgumentException: Cannot format given Object as a
> Number
> 
>             at java.text.DecimalFormat.format(DecimalFormat.java:480)
> 
>             at java.text.Format.format(Format.java:133)
> 
>             at
> org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
> tToString(AbstractNumberConverter.java:109)
> 
>             at
> org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
> solverConverter.java:84)
> 
>  
> 
> I'm using List<SelectOption> to populate the DropDownChoice, as per the
> online example:
> 
>  
> 
> http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
> ml
> 
>  
> 
> The only change I made to SelectOption is to set the 'value' field to an
> Integer (which I need for my model).
> 
>  
> 
> Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
> the label/value pairs as the labels show up properly.
> 
>  
> 
> Thanks,
> 
>  
> 
> Michael
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-throws-IllegalArgumentException-with-Integer-values-tp17139227p17150771.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Anyone? Was hoping for some input here ;-)

-----Original Message-----
From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
Sent: Thursday, May 08, 2008 6:35 PM
To: users@wicket.apache.org
Subject: RE: DropDownChoice throws IllegalArgumentException with Integer
values

Okay, I just stepped through this and getting the feeling that 'somehow'
the label is being passed on to the model. Now, if the label is '1' it
works fine, but if it's '1 day', then I get that error.

The question here is: why is the label being passed back to the model?
Doesn't make any sense - I'm using a ChoiceRenderer as such:

new ChoiceRenderer("label", "value")

Do I also need to add some kind of converter to properly assign the
model?

Any input would be appreciated.

Michael

-----Original Message-----
From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
Sent: Thursday, May 08, 2008 5:19 PM
To: users@wicket.apache.org
Subject: DropDownChoice throws IllegalArgumentException with Integer
values

This is the error I'm getting:

 

[DEBUG LoadAdDataInterceptor] Loaded
AdData:com.evite.common.ad.model.AdData@17ceb9b 

[ERROR RequestCycle] Cannot format given Object as a Number 

java.lang.IllegalArgumentException: Cannot format given Object as a
Number

            at java.text.DecimalFormat.format(DecimalFormat.java:480)

            at java.text.Format.format(Format.java:133)

            at
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
tToString(AbstractNumberConverter.java:109)

            at
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
solverConverter.java:84)

 

I'm using List<SelectOption> to populate the DropDownChoice, as per the
online example:

 

http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
ml

 

The only change I made to SelectOption is to set the 'value' field to an
Integer (which I need for my model).

 

Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
the label/value pairs as the labels show up properly.

 

Thanks,

 

Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: DropDownChoice throws IllegalArgumentException with Integer values

Posted by Michael Mehrle <mi...@ask.com>.
Okay, I just stepped through this and getting the feeling that 'somehow'
the label is being passed on to the model. Now, if the label is '1' it
works fine, but if it's '1 day', then I get that error.

The question here is: why is the label being passed back to the model?
Doesn't make any sense - I'm using a ChoiceRenderer as such:

new ChoiceRenderer("label", "value")

Do I also need to add some kind of converter to properly assign the
model?

Any input would be appreciated.

Michael

-----Original Message-----
From: Michael Mehrle [mailto:michael.mehrle@ask.com] 
Sent: Thursday, May 08, 2008 5:19 PM
To: users@wicket.apache.org
Subject: DropDownChoice throws IllegalArgumentException with Integer
values

This is the error I'm getting:

 

[DEBUG LoadAdDataInterceptor] Loaded
AdData:com.evite.common.ad.model.AdData@17ceb9b 

[ERROR RequestCycle] Cannot format given Object as a Number 

java.lang.IllegalArgumentException: Cannot format given Object as a
Number

            at java.text.DecimalFormat.format(DecimalFormat.java:480)

            at java.text.Format.format(Format.java:133)

            at
org.apache.wicket.util.convert.converters.AbstractNumberConverter.conver
tToString(AbstractNumberConverter.java:109)

            at
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyRe
solverConverter.java:84)

 

I'm using List<SelectOption> to populate the DropDownChoice, as per the
online example:

 

http://cwiki.apache.org/WICKET/another-dropdownchoice-example-by-adam.ht
ml

 

The only change I made to SelectOption is to set the 'value' field to an
Integer (which I need for my model).

 

Anyone any ideas as to what's going on? I'm pretty sure I didn't swap
the label/value pairs as the labels show up properly.

 

Thanks,

 

Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org