You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Matt Welch <ma...@welchkin.net> on 2009/02/23 05:55:45 UTC

LDM with Generics for DropDownChoice

I'm sure I should know this but I can't seem to get it right. I have a
LoadableDetachableModel as follows:


	private class AllUserModel extends LoadableDetachableModel<List<User>>{
		protected List<User> load() {
			return userService().findAllUsers();
		}
	}


I'm trying to use this as the Choices model in a DropDownChoice, but no
luck. I'm sure I'm missing an <E> or a <T> or a<?> somewhere but I at a lost
as to what the exact problem is. I've been a consumer of generics forever,
but actually being on the creation side is a bit new to me. 

-- 
View this message in context: http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22155211.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: LDM with Generics for DropDownChoice

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Wed, 25 Feb 2009, Timo Rantalaiho wrote:
> I'd say that ListView is wrong here.
> 
> I created a new Jira issue on fixing that
> 
>   https://issues.apache.org/jira/browse/WICKET-2126
> 
> and will do if there are no objections or better ideas. 

Well, Igor objected very convincingly :) 

So now there remains the chance of narrowing the 
DropDownChoice choices list model back to the wildcardless
form. Or do you have other ideas of how to resolve this?

Best wishes,
Timo


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


Re: LDM with Generics for DropDownChoice

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 24 Feb 2009, Matthew Hanlon wrote:
> I've always handled the typing problem with DropDownChoice and my list
> models by "just ignoring it" and not applying type parameters to the
> DropDownChoice.  This is because if I use the same IModel<List<? extends
> Foo>> for a ListView, then I get an error in the ListView's constructor.
> Is there a good solution for both, other that having two types of
> IModel<List<?>> for the same object, one with the "? extends" and one
> without, or ignoring the type parameters on DropDownChoice, as I always have
> in the past?

Raw types shouldn't be used at all so we should find a 
better solution.

Based on this

  https://issues.apache.org/jira/browse/WICKET-1512

I'd say that ListView is wrong here.

I created a new Jira issue on fixing that

  https://issues.apache.org/jira/browse/WICKET-2126

and will do if there are no objections or better ideas. 

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

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


Re: LDM with Generics for DropDownChoice

Posted by Matthew Hanlon <mr...@gmail.com>.
I've always handled the typing problem with DropDownChoice and my list
models by "just ignoring it" and not applying type parameters to the
DropDownChoice.  This is because if I use the same IModel<List<? extends
Foo>> for a ListView, then I get an error in the ListView's constructor.
Is there a good solution for both, other that having two types of
IModel<List<?>> for the same object, one with the "? extends" and one
without, or ignoring the type parameters on DropDownChoice, as I always have
in the past?

Regards,
Matthew.

On Mon, Feb 23, 2009 at 09:46, Matt Welch <ma...@welchkin.net> wrote:

>
>
> Martijn Dashorst wrote:
> >
> >> Just to make sure I'm understanding this; yuo're saying I have to create
> >> a
> >> variable and then assign the variable instead of just being able to pass
> >> "new AllUsersModel()" to the DropDownChoice constructor?
> >
> > Nope, just change your model supertype from List<Foo> to List<? extends
> > Foo>
> >
> >> That just seems.... odd.
> >
> > Welcome to Java generics...
> >
> Thanks. It's working now.
>
>
>        private class AllUsersModel extends LoadableDetachableModel<List<?
> extends
> User>>{
>                protected List<User> load() {
>                        return userService.findAllUsers();
>                }
>        }
>
> --
> View this message in context:
> http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22164005.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
>
>


-- 
Matthew Rollins Hanlon
http://squareoftwo.org
_____________________
Hanlon's Razor:
"Never attribute to malice that which can be adequately explained by
stupidity."
http://wikipedia.org/wiki/Hanlon's_razor

Re: LDM with Generics for DropDownChoice

Posted by Matt Welch <ma...@welchkin.net>.

Martijn Dashorst wrote:
> 
>> Just to make sure I'm understanding this; yuo're saying I have to create
>> a
>> variable and then assign the variable instead of just being able to pass
>> "new AllUsersModel()" to the DropDownChoice constructor?
> 
> Nope, just change your model supertype from List<Foo> to List<? extends
> Foo>
> 
>> That just seems.... odd.
> 
> Welcome to Java generics...
> 
Thanks. It's working now. 


	private class AllUsersModel extends LoadableDetachableModel<List<? extends
User>>{
		protected List<User> load() {
			return userService.findAllUsers();
		}
	}

-- 
View this message in context: http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22164005.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: LDM with Generics for DropDownChoice

Posted by Martijn Dashorst <ma...@gmail.com>.
On Mon, Feb 23, 2009 at 2:55 PM, Matt Welch <ma...@welchkin.net> wrote:
>
> Just to make sure I'm understanding this; yuo're saying I have to create a
> variable and then assign the variable instead of just being able to pass
> "new AllUsersModel()" to the DropDownChoice constructor?

Nope, just change your model supertype from List<Foo> to List<? extends Foo>

> That just seems.... odd.

Welcome to Java generics...

Martijn

-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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


Re: LDM with Generics for DropDownChoice

Posted by Matt Welch <ma...@welchkin.net>.
Just to make sure I'm understanding this; yuo're saying I have to create a
variable and then assign the variable instead of just being able to pass
"new AllUsersModel()" to the DropDownChoice constructor?

That just seems.... odd.





Jeremy Thomerson-5 wrote:
> 
> IIRC, DropDownChoice requires a declaration like such:
> 
> IModel<List<? extends Foo>>
> 
> So, this should work:
> 
> IModel<List<? extends Foo>> choices = new AllUserModel();
> 
> I've been meaning to ask on the dev list why that is.  Being forced to
> declare the "? extends User" for a model like yours seems to add
> complexity,
> and force a local variable.  I haven't looked at it that much, but I know
> that every time I've had to declare one, I always think "that's weird".
> 
> On Sun, Feb 22, 2009 at 10:55 PM, Matt Welch <ma...@welchkin.net> wrote:
> 
>>
>> I'm sure I should know this but I can't seem to get it right. I have a
>> LoadableDetachableModel as follows:
>>
>>
>>        private class AllUserModel extends
>> LoadableDetachableModel<List<User>>{
>>                protected List<User> load() {
>>                        return userService().findAllUsers();
>>                }
>>        }
>>
>>
>> I'm trying to use this as the Choices model in a DropDownChoice, but no
>> luck. I'm sure I'm missing an <E> or a <T> or a<?> somewhere but I at a
>> lost
>> as to what the exact problem is. I've been a consumer of generics
>> forever,
>> but actually being on the creation side is a bit new to me.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22155211.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
>>
>>
> 
> 
> -- 
> Jeremy Thomerson
> http://www.wickettraining.com
> 
> 

-- 
View this message in context: http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22161940.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: LDM with Generics for DropDownChoice

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Sun, 22 Feb 2009, Jeremy Thomerson wrote:
> I've been meaning to ask on the dev list why that is.  Being forced to
> declare the "? extends User" for a model like yours seems to add complexity,
> and force a local variable.  I haven't looked at it that much, but I know
> that every time I've had to declare one, I always think "that's weird".

Then you can have a collection of subclass objects as well, 
e.g. this does not compile

  List<Serializable> foo = new ArrayList<String>();

but this does

  List<? extends Serializable> bar = new ArrayList<String>();

You don't really miss the "? extends" thing until you need 
it :) E.g. you have user dropdown that shows Users and then 
you want to use it to list objcets of Admin extends User.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

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


Re: LDM with Generics for DropDownChoice

Posted by Jeremy Thomerson <je...@wickettraining.com>.
IIRC, DropDownChoice requires a declaration like such:

IModel<List<? extends Foo>>

So, this should work:

IModel<List<? extends Foo>> choices = new AllUserModel();

I've been meaning to ask on the dev list why that is.  Being forced to
declare the "? extends User" for a model like yours seems to add complexity,
and force a local variable.  I haven't looked at it that much, but I know
that every time I've had to declare one, I always think "that's weird".

On Sun, Feb 22, 2009 at 10:55 PM, Matt Welch <ma...@welchkin.net> wrote:

>
> I'm sure I should know this but I can't seem to get it right. I have a
> LoadableDetachableModel as follows:
>
>
>        private class AllUserModel extends
> LoadableDetachableModel<List<User>>{
>                protected List<User> load() {
>                        return userService().findAllUsers();
>                }
>        }
>
>
> I'm trying to use this as the Choices model in a DropDownChoice, but no
> luck. I'm sure I'm missing an <E> or a <T> or a<?> somewhere but I at a
> lost
> as to what the exact problem is. I've been a consumer of generics forever,
> but actually being on the creation side is a bit new to me.
>
> --
> View this message in context:
> http://www.nabble.com/LDM-with-Generics-for-DropDownChoice-tp22155211p22155211.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
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com