Re: Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-13 Thread Jeremy Thomerson
On Sat, Feb 12, 2011 at 8:49 AM, Willis Blackburn wbo...@panix.com wrote:

 jer...@wickettraining.com wrote:
 
  On Sat, Feb 12, 2011 at 7:56 AM, Willis Blackburn wbo...@panix.com
  wrote:
 
  As a side note, rarely should you ever use Model class for a list of
  things,
  especially things loaded from a database.  If you then pass that model to
  a
  component, all the things in it will be serialized.
 
 

 I'm sorry that I said that I loaded the list from a database, since that
 has
 apparently created a distraction from my key point, which is that if you
 start with a ListC and pass it to Model.listOf, you get back something
 that is not a ListC, which is undesirable and perhaps unnecessary.


I understood your key point, which is why I said as a side note but my
point still remains.  Loading a list and then sticking it into Model class
is in almost all cases a *bad* idea.


  So use the Model constructors instead.  The factory methods are just
 there
  to help remove some verbosity related to generics.
 

 Have you tried this yourself?  Because it doesn't work.  You can only
 instantiate Model with a Serializable instance, and java.util.List does not
 implement Serializable.  The whole point of the ofList method is to
 generate
 serializable lists, and the documentation even says so: This factory
 method
 will automatically rebuild a nonserializable list into a serializable one.
 You're confusing Model.listOf with Model.of.


Sorry, yes, it was early and I wasn't paying attention.  Hadn't had my
Wheaties yet :)  Have you looked at the ListModel class?  It may help with
what you're looking for.

Do you have a suggestion for a better method signature for that method?  The
problem you are describing, if I understand your description correctly, is a
problem with Java generics, not with Wicket's use of them.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-13 Thread Scott Swank
A simpler API would be:

public static C IModelListC ofList(final List? extends C list)

or even:

public static C IModelListC ofList(final ListC list)

since you are calling this method with a specific List, and hence the
type of the List is known.

Scott


On Sun, Feb 13, 2011 at 11:32 AM, Jeremy Thomerson
jer...@wickettraining.com wrote:
 On Sat, Feb 12, 2011 at 8:49 AM, Willis Blackburn wbo...@panix.com wrote:

 jer...@wickettraining.com wrote:
 
  On Sat, Feb 12, 2011 at 7:56 AM, Willis Blackburn wbo...@panix.com
  wrote:
 
  As a side note, rarely should you ever use Model class for a list of
  things,
  especially things loaded from a database.  If you then pass that model to
  a
  component, all the things in it will be serialized.
 
 

 I'm sorry that I said that I loaded the list from a database, since that
 has
 apparently created a distraction from my key point, which is that if you
 start with a ListC and pass it to Model.listOf, you get back something
 that is not a ListC, which is undesirable and perhaps unnecessary.


 I understood your key point, which is why I said as a side note but my
 point still remains.  Loading a list and then sticking it into Model class
 is in almost all cases a *bad* idea.


  So use the Model constructors instead.  The factory methods are just
 there
  to help remove some verbosity related to generics.
 

 Have you tried this yourself?  Because it doesn't work.  You can only
 instantiate Model with a Serializable instance, and java.util.List does not
 implement Serializable.  The whole point of the ofList method is to
 generate
 serializable lists, and the documentation even says so: This factory
 method
 will automatically rebuild a nonserializable list into a serializable one.
 You're confusing Model.listOf with Model.of.


 Sorry, yes, it was early and I wasn't paying attention.  Hadn't had my
 Wheaties yet :)  Have you looked at the ListModel class?  It may help with
 what you're looking for.

 Do you have a suggestion for a better method signature for that method?  The
 problem you are describing, if I understand your description correctly, is a
 problem with Java generics, not with Wicket's use of them.

 --
 Jeremy Thomerson
 http://wickettraining.com
 *Need a CMS for Wicket?  Use Brix! http://brixcms.org*


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



Re: Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-13 Thread Willis Blackburn

On Feb 13, 2011, at 2:33 PM, jer...@wickettraining.com [via Apache Wicket] 
wrote:

 I understood your key point, which is why I said as a side note but my 
 point still remains.  Loading a list and then sticking it into Model class 
 is in almost all cases a *bad* idea. 


I agree with you!  But nevertheless there are some cases in which a 
ModelListC makes sense--even when a database is involved.  If, for example, 
the List is small, and is expensive to generate from the database, then 
serializing it and keeping it in the session could be the best approach.


 Sorry, yes, it was early and I wasn't paying attention.  Hadn't had my 
 Wheaties yet :)  Have you looked at the ListModel class?  It may help with 
 what you're looking for. 
 
 Do you have a suggestion for a better method signature for that method?  The 
 problem you are describing, if I understand your description correctly, is a 
 problem with Java generics, not with Wicket's use of them. 


I hadn't seen ListModel, but thanks--it looks like a good solution.  Although 
it sort of makes Model.listOf even more mysterious, in that Model.listOf 
doesn't create a ListModel.

My suggestion for Model.listOf is simply:

public static C IModelListC ofList(final ListC list)

In other words it takes a ListC and return an IModelListC, which is (I 
think) what you'd expect.

Maybe the thinking is that Model.listOf may need to return a list of some 
serializable subclass of C, if C is not serializable itself.

W





-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Unfriendly-Model-ofList-etc-methods-can-anything-be-done-tp3302712p3304062.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-12 Thread Willis Blackburn

I'm constantly running into problems with this method:

public static C IModelList? extends C ofList(final List? extends C
list)

This says that ofList takes, as a parameter, a List of C or some subclass of
C, and returns a List of C or of some subclass of C.

The problem that I keep having is that the type of the input list and the
type of the output list may not be the same.  I think that in practice they
are, but the compiler does not know that.  If C = StringedInstrument then
the parameter may be ListViolin while the returned list may be
ListGuitar.

So every time I call Model.listOf, the type parameter of my List becomes
hazy, which has annoying downstream effects.  If I load a
ListStringedInstrument from a database, then pass it to Model.ofList, I
wind up with a List? extends StringedInstrument--the compiler has no idea
what the generic type of the List is, only that whatever it is, it is
compatible with StringedInstrument.  I can still get StringedInstrument
instances out of the List, but I can't pass it to any method (like a
component constructor) that takes a ListStringedInstrument or an
IModelListStringedInstrument without ugly casting.

Since Model.ofList must return a list that is compatible with the original
list--it's a wrapper, not a transformer--can't it just take ListC and
return ListC?

Same goes for the other ofCollection-type methods.

-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Unfriendly-Model-ofList-etc-methods-can-anything-be-done-tp3302712p3302712.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-12 Thread Jeremy Thomerson
On Sat, Feb 12, 2011 at 7:56 AM, Willis Blackburn wbo...@panix.com wrote:


 I'm constantly running into problems with this method:

 public static C IModelList? extends C ofList(final List? extends C
 list)

 This says that ofList takes, as a parameter, a List of C or some subclass
 of
 C, and returns a List of C or of some subclass of C.

 The problem that I keep having is that the type of the input list and the
 type of the output list may not be the same.  I think that in practice they
 are, but the compiler does not know that.  If C = StringedInstrument then
 the parameter may be ListViolin while the returned list may be
 ListGuitar.

 So every time I call Model.listOf, the type parameter of my List becomes
 hazy, which has annoying downstream effects.  If I load a
 ListStringedInstrument from a database, then pass it to Model.ofList, I
 wind up with a List? extends StringedInstrument--the compiler has no idea
 what the generic type of the List is, only that whatever it is, it is
 compatible with StringedInstrument.


As a side note, rarely should you ever use Model class for a list of things,
especially things loaded from a database.  If you then pass that model to a
component, all the things in it will be serialized.

You should be using LoadableDetachableModel and have the load from
database logic in the load method.

Model is just a dataholder implementation of IModel that should typically
only be used for transient data (data that can't be loaded from somewhere)
because it must serialize whatever you get it.  This is especially bad
whenever you are dealing with any collection of things.


  I can still get StringedInstrument
 instances out of the List, but I can't pass it to any method (like a
 component constructor) that takes a ListStringedInstrument or an
 IModelListStringedInstrument without ugly casting.

 Since Model.ofList must return a list that is compatible with the original
 list--it's a wrapper, not a transformer--can't it just take ListC and
 return ListC?

 Same goes for the other ofCollection-type methods.


So use the Model constructors instead.  The factory methods are just there
to help remove some verbosity related to generics.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: Unfriendly Model.ofList etc. methods; can anything be done?

2011-02-12 Thread Willis Blackburn


jer...@wickettraining.com wrote:
 
 On Sat, Feb 12, 2011 at 7:56 AM, Willis Blackburn wbo...@panix.com
 wrote:
 
 As a side note, rarely should you ever use Model class for a list of
 things,
 especially things loaded from a database.  If you then pass that model to
 a
 component, all the things in it will be serialized.
 
 

I'm sorry that I said that I loaded the list from a database, since that has
apparently created a distraction from my key point, which is that if you
start with a ListC and pass it to Model.listOf, you get back something
that is not a ListC, which is undesirable and perhaps unnecessary.



 So use the Model constructors instead.  The factory methods are just there
 to help remove some verbosity related to generics.
 

Have you tried this yourself?  Because it doesn't work.  You can only
instantiate Model with a Serializable instance, and java.util.List does not
implement Serializable.  The whole point of the ofList method is to generate
serializable lists, and the documentation even says so: This factory method
will automatically rebuild a nonserializable list into a serializable one. 
You're confusing Model.listOf with Model.of.

W


-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Unfriendly-Model-ofList-etc-methods-can-anything-be-done-tp3302712p3302752.html
Sent from the Users forum mailing list archive at Nabble.com.

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