generics in Wicket

View: New views
14 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 - 3 | Next >

AW: generics in Wicket

by Korbinian Bachl-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BIG +1 from me on this post!
 
especially as everyone can set his compiler to ignore the generics when he
dont want them while they save much time for devs that use them          
 
Regards
 
 
 
  _____  

Von: Philip A. Chapman [mailto:pchapman@...]
Gesendet: Montag, 19. März 2007 19:26
An: wicket-dev@...
Betreff: Re: generics in Wicket



Guys,

I've used generics with 2.0 at length, and absolutely love them.  I am a
huge fan of catching a problem early with compile-time errors rather than
finding out later that I'm returning the wrong type from a model or that my
Formatter is expecting a different type.  Yes, for a while the angle
brackets are ugly and annoying.  Heck the first time I saw C style language,
I thought that all the braces where ugly as sin.  When I first began using
annotations, I found it hard to read.  Now?  I've used all these things and
have learned how to read them without having to stare at them a long time.
Now I can move on to using them to make my code better.

You do not *have* to use generics even with a generified framework.  You
will have to do a lot of casting and get a lot of compiler warnings, but it
is not required.  Nothing keeps you from defining a variable as a ListChoice
rather than ListChoice<MyUserBean>.  I, on the other hand use
ListChoice<MyUserBean> extensively.  To take that away would require that I
touch a lot of code.  For you, it requires that you ignore compiler
warnings.

All in all, I don't care much about the constructor change, but I consider
generics to be a must-have.

Anyway, that's my 2 cents.  Your mileage may vary, of course.

On Sun, 2007-03-18 at 22:22 -0700, Ryan Holmes wrote:

Sure, but converters shouldn't necessarily be more tightly coupled to  

models either. Converters might use more fine grained types than a  

model, for instance (although I do see your point -- if objects are  

naturally tightly coupled there's no reason to pretend they're not).



I guess I'm looking at this from a fundamentally different point of  

view: I've been getting by just fine with Wicket 1.2 (better than  

fine -- I freakin' love it) and haven't once been bothered by the  

lack of generics. I end up with maybe one or two casts in a page  

which just isn't a big deal. At the same time, generic components  

seem to add little and cost a lot in terms of productivity,  

readability and upgrade effort.



So I totally agree that some things are nicer with generics. But that  

doesn't mean that generic components are the right design. I mean,  

are there demonstrable advantages to generic components that make  

Wicket a better framework and/or improve the API from a user's point  

of view? Or are generic components strictly a side-effect of generic  

models?



-Ryan



On Mar 18, 2007, at 6:35 PM, Igor Vaynberg wrote:



> the thing is the model ties into a few places in the component

>

> for example IConverter Component.getConverter(). it would be nice  

> to say new

> WebMarkupContainer<Person> { IConverter<Person> getConverter() {...}}

>

> things like that

>

> -igor

>

>

> On 3/18/07, Eelco Hillenius <eelco.hillenius@...> wrote:

>>

>> Hi Ryan,

>>

>> The problem is - I found out later - that we can't really generify

>> models in a meaningful way without generifying components as well. At

>> least, I haven't found a good way.

>>

>> Do you have concrete suggestions or a proposal of how we could

>> implement generics in a meaningful but non-obstrusive way?

>>

>> Eelco

>>

>>

>> On 3/18/07, Ryan Holmes <ryan@...> wrote:

>> > I think generic components are a mistake for several reasons. Not

>> > only is the snippet below ugly and redundant, it doesn't even  

>> save a

>> > cast if you're using a CompoundPropertyModel (which is the most

>> > common case in my app). Well, I guess you save one cast, but that's

>> > for the parent component's model, not for the form components

>> > themselves.

>> >

>> > At least for FormComponents, it's relatively obvious that a

>> > component's type == its model type. But what does it mean to  

>> specify

>> > the type for a Panel, Link, WebMarkupContainer, etc. when you're  

>> not

>> > even going to assign a model to the component (again, a fairly  

>> common

>> > case)? I think classes that make sense as generics don't have this

>> > problem -- they always hold, accept or return objects of their

>> > specified type.

>> >

>> > A lot of this boils down to the fact that a component's type

>> > parameter really has little to do with the component itself.  

>> It's for

>> > the underlying model (including validation/conversion to the  

>> model's

>> > object). Specifying the model's type in the component tightly  

>> couples

>> > the two together, which clashes with Wicket's concept of models as

>> > independent and dynamically resolvable objects (not to mention

>> > clashing with MVC in general).

>> >

>> > So, I completely agree with everything you said below and just  

>> wanted

>> > to throw out a "-1" for generic components hopefully before a final

>> > decision is made.

>> >

>> > -Ryan

>> >

>> >

>> > On Mar 6, 2007, at 9:57 PM, Eelco Hillenius wrote:

>> >

>> > > Hi,

>> > >

>> > > I think we went overboard applying generics in Wicket.

>> > >

>> > > Things like:

>> > > TextField<Integer> integerTextField = new TextField<Integer>

>> (this,

>> > > "integerProperty", Integer.class);

>> > >

>> > > are just horrible imo. Sure, you can do:

>> > >

>> > > Integer i = integerTextField.getModelObject();

>> > >

>> > > instead of:

>> > >

>> > > Integer i = (Integer)integerTextField.getModelObject();

>> > >

>> > > but that's about the whole great benefit of generic components  

>> for the

>> > > price of about twice the verbosity.

>> > >

>> > > Also, calling getModelObject is the kind of convenience method  

>> that

>> > > grew upon us but that I personally never liked. It saves an  

>> ugly model

>> > > check, fine, but in general I think users should try to  

>> directly work

>> > > with models and their underlying objects instead.

>> > >

>> > > I can see the method come in handy in list views (on  

>> ListItem), though

>> > > then again, you know the model object would never be null  

>> there so

>> > > getModel().getObject() would work as well.

>> > >

>> > > Anyway, what I'd like us to consider is to de-generify  

>> components and

>> > > only keep it for models. For certain components (like  

>> ListView) we/

>> > > users can decide to introduce it, but the general case would  

>> be to not

>> > > to.

>> > >

>> > > Thoughts? Screams?

>> > >

>> > > Eelco

>> >

>> >

>>




--

Philip A. Chapman



Desktop and Web Application Development:

Java, .NET, PostgreSQL, MySQL, MSSQL

Linux, Windows 2000, Windows XP


Re: generics in Wicket

by Ryan Holmes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's not that I don't like generics -- I just don't think Component  
makes sense as a generic class because it seems like the majority of  
use cases don't call for specifying a model type.

Let me ask you, do you specify the type for form components even when  
you're using a CompoundPropertyModel (i.e. when you're never going to  
call getModel() or getModelObject() directly on those components)?

And what about MarkupContainers and other components that you usually  
don't assign a model to?

-Ryan


On Mar 19, 2007, at 11:25 AM, Philip A. Chapman wrote:

> Guys,
>
> I've used generics with 2.0 at length, and absolutely love them.  I  
> am a huge fan of catching a problem early with compile-time errors  
> rather than finding out later that I'm returning the wrong type  
> from a model or that my Formatter is expecting a different type.  
> Yes, for a while the angle brackets are ugly and annoying.  Heck  
> the first time I saw C style language, I thought that all the  
> braces where ugly as sin.  When I first began using annotations, I  
> found it hard to read.  Now?  I've used all these things and have  
> learned how to read them without having to stare at them a long  
> time.  Now I can move on to using them to make my code better.
>
> You do not *have* to use generics even with a generified  
> framework.  You will have to do a lot of casting and get a lot of  
> compiler warnings, but it is not required.  Nothing keeps you from  
> defining a variable as a ListChoice rather than  
> ListChoice<MyUserBean>.  I, on the other hand use  
> ListChoice<MyUserBean> extensively.  To take that away would  
> require that I touch a lot of code.  For you, it requires that you  
> ignore compiler warnings.
>
> All in all, I don't care much about the constructor change, but I  
> consider generics to be a must-have.
>
> Anyway, that's my 2 cents.  Your mileage may vary, of course.
>
> On Sun, 2007-03-18 at 22:22 -0700, Ryan Holmes wrote:
>> Sure, but converters shouldn't necessarily be more tightly coupled  
>> to models either. Converters might use more fine grained types  
>> than a model, for instance (although I do see your point -- if  
>> objects are naturally tightly coupled there's no reason to pretend  
>> they're not). I guess I'm looking at this from a fundamentally  
>> different point of view: I've been getting by just fine with  
>> Wicket 1.2 (better than fine -- I freakin' love it) and haven't  
>> once been bothered by the lack of generics. I end up with maybe  
>> one or two casts in a page which just isn't a big deal. At the  
>> same time, generic components seem to add little and cost a lot in  
>> terms of productivity, readability and upgrade effort. So I  
>> totally agree that some things are nicer with generics. But that  
>> doesn't mean that generic components are the right design. I mean,  
>> are there demonstrable advantages to generic components that make  
>> Wicket a better framework and/or improve the API from a user's  
>> point of view? Or are generic components strictly a side-effect of  
>> generic models? -Ryan On Mar 18, 2007, at 6:35 PM, Igor Vaynberg  
>> wrote: > the thing is the model ties into a few places in the  
>> component > > for example IConverter Component.getConverter(). it  
>> would be nice > to say new > WebMarkupContainer<Person>  
>> { IConverter<Person> getConverter() {...}} > > things like that >  
>> > -igor > > > On 3/18/07, Eelco Hillenius  
>> <eelco.hillenius@...> wrote: >> >> Hi Ryan, >> >> The  
>> problem is - I found out later - that we can't really generify >>  
>> models in a meaningful way without generifying components as well.  
>> At >> least, I haven't found a good way. >> >> Do you have  
>> concrete suggestions or a proposal of how we could >> implement  
>> generics in a meaningful but non-obstrusive way? >> >> Eelco >> >>  
>> >> On 3/18/07, Ryan Holmes <ryan@...> wrote: >> > I  
>> think generic components are a mistake for several reasons. Not >>  
>> > only is the snippet below ugly and redundant, it doesn't even >>  
>> save a >> > cast if you're using a CompoundPropertyModel (which is  
>> the most >> > common case in my app). Well, I guess you save one  
>> cast, but that's >> > for the parent component's model, not for  
>> the form components >> > themselves. >> > >> > At least for  
>> FormComponents, it's relatively obvious that a >> > component's  
>> type == its model type. But what does it mean to >> specify >> >  
>> the type for a Panel, Link, WebMarkupContainer, etc. when you're  
>> >> not >> > even going to assign a model to the component (again,  
>> a fairly >> common >> > case)? I think classes that make sense as  
>> generics don't have this >> > problem -- they always hold, accept  
>> or return objects of their >> > specified type. >> > >> > A lot of  
>> this boils down to the fact that a component's type >> > parameter  
>> really has little to do with the component itself. >> It's for >>  
>> > the underlying model (including validation/conversion to the >>  
>> model's >> > object). Specifying the model's type in the component  
>> tightly >> couples >> > the two together, which clashes with  
>> Wicket's concept of models as >> > independent and dynamically  
>> resolvable objects (not to mention >> > clashing with MVC in  
>> general). >> > >> > So, I completely agree with everything you  
>> said below and just >> wanted >> > to throw out a "-1" for generic  
>> components hopefully before a final >> > decision is made. >> > >>  
>> > -Ryan >> > >> > >> > On Mar 6, 2007, at 9:57 PM, Eelco Hillenius  
>> wrote: >> > >> > > Hi, >> > > >> > > I think we went overboard  
>> applying generics in Wicket. >> > > >> > > Things like: >> > >  
>> TextField<Integer> integerTextField = new TextField<Integer> >>  
>> (this, >> > > "integerProperty", Integer.class); >> > > >> > > are  
>> just horrible imo. Sure, you can do: >> > > >> > > Integer i =  
>> integerTextField.getModelObject(); >> > > >> > > instead of: >> >  
>> > >> > > Integer i = (Integer)integerTextField.getModelObject();  
>> >> > > >> > > but that's about the whole great benefit of generic  
>> components >> for the >> > > price of about twice the verbosity.  
>> >> > > >> > > Also, calling getModelObject is the kind of  
>> convenience method >> that >> > > grew upon us but that I  
>> personally never liked. It saves an >> ugly model >> > > check,  
>> fine, but in general I think users should try to >> directly work  
>> >> > > with models and their underlying objects instead. >> > > >>  
>> > > I can see the method come in handy in list views (on >>  
>> ListItem), though >> > > then again, you know the model object  
>> would never be null >> there so >> > > getModel().getObject()  
>> would work as well. >> > > >> > > Anyway, what I'd like us to  
>> consider is to de-generify >> components and >> > > only keep it  
>> for models. For certain components (like >> ListView) we/ >> > >  
>> users can decide to introduce it, but the general case would >> be  
>> to not >> > > to. >> > > >> > > Thoughts? Screams? >> > > >> > >  
>> Eelco >> > >> > >>
> -- Philip A. Chapman Desktop and Web Application Development:  
> Java, .NET, PostgreSQL, MySQL, MSSQL Linux, Windows 2000, Windows XP


Re: generics in Wicket

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

what about the cases where it is very nice to have?

ListView(String,IModel<T>,IModel<List<T>>)

or

DropDownChoice(String,IModel<T>,IModel<List<T>>,IChoiceRenderer<T>)

im not arguing for or against, but there are cases where it is very nice to
have them, especially for newbies. when a newbie looks at the above they
know whats going on as opposed to

DropDownChoice(String,IModel,IModel,IChoiceRenderer)

-igor


On 3/19/07, Ryan Holmes <ryan@...> wrote:

>
> It's not that I don't like generics -- I just don't think Component
> makes sense as a generic class because it seems like the majority of
> use cases don't call for specifying a model type.
>
> Let me ask you, do you specify the type for form components even when
> you're using a CompoundPropertyModel (i.e. when you're never going to
> call getModel() or getModelObject() directly on those components)?
>
> And what about MarkupContainers and other components that you usually
> don't assign a model to?
>
> -Ryan
>
>
> On Mar 19, 2007, at 11:25 AM, Philip A. Chapman wrote:
>
> > Guys,
> >
> > I've used generics with 2.0 at length, and absolutely love them.  I
> > am a huge fan of catching a problem early with compile-time errors
> > rather than finding out later that I'm returning the wrong type
> > from a model or that my Formatter is expecting a different type.
> > Yes, for a while the angle brackets are ugly and annoying.  Heck
> > the first time I saw C style language, I thought that all the
> > braces where ugly as sin.  When I first began using annotations, I
> > found it hard to read.  Now?  I've used all these things and have
> > learned how to read them without having to stare at them a long
> > time.  Now I can move on to using them to make my code better.
> >
> > You do not *have* to use generics even with a generified
> > framework.  You will have to do a lot of casting and get a lot of
> > compiler warnings, but it is not required.  Nothing keeps you from
> > defining a variable as a ListChoice rather than
> > ListChoice<MyUserBean>.  I, on the other hand use
> > ListChoice<MyUserBean> extensively.  To take that away would
> > require that I touch a lot of code.  For you, it requires that you
> > ignore compiler warnings.
> >
> > All in all, I don't care much about the constructor change, but I
> > consider generics to be a must-have.
> >
> > Anyway, that's my 2 cents.  Your mileage may vary, of course.
> >
> > On Sun, 2007-03-18 at 22:22 -0700, Ryan Holmes wrote:
> >> Sure, but converters shouldn't necessarily be more tightly coupled
> >> to models either. Converters might use more fine grained types
> >> than a model, for instance (although I do see your point -- if
> >> objects are naturally tightly coupled there's no reason to pretend
> >> they're not). I guess I'm looking at this from a fundamentally
> >> different point of view: I've been getting by just fine with
> >> Wicket 1.2 (better than fine -- I freakin' love it) and haven't
> >> once been bothered by the lack of generics. I end up with maybe
> >> one or two casts in a page which just isn't a big deal. At the
> >> same time, generic components seem to add little and cost a lot in
> >> terms of productivity, readability and upgrade effort. So I
> >> totally agree that some things are nicer with generics. But that
> >> doesn't mean that generic components are the right design. I mean,
> >> are there demonstrable advantages to generic components that make
> >> Wicket a better framework and/or improve the API from a user's
> >> point of view? Or are generic components strictly a side-effect of
> >> generic models? -Ryan On Mar 18, 2007, at 6:35 PM, Igor Vaynberg
> >> wrote: > the thing is the model ties into a few places in the
> >> component > > for example IConverter Component.getConverter(). it
> >> would be nice > to say new > WebMarkupContainer<Person>
> >> { IConverter<Person> getConverter() {...}} > > things like that >
> >> > -igor > > > On 3/18/07, Eelco Hillenius
> >> <eelco.hillenius@...> wrote: >> >> Hi Ryan, >> >> The
> >> problem is - I found out later - that we can't really generify >>
> >> models in a meaningful way without generifying components as well.
> >> At >> least, I haven't found a good way. >> >> Do you have
> >> concrete suggestions or a proposal of how we could >> implement
> >> generics in a meaningful but non-obstrusive way? >> >> Eelco >> >>
> >> >> On 3/18/07, Ryan Holmes <ryan@...> wrote: >> > I
> >> think generic components are a mistake for several reasons. Not >>
> >> > only is the snippet below ugly and redundant, it doesn't even >>
> >> save a >> > cast if you're using a CompoundPropertyModel (which is
> >> the most >> > common case in my app). Well, I guess you save one
> >> cast, but that's >> > for the parent component's model, not for
> >> the form components >> > themselves. >> > >> > At least for
> >> FormComponents, it's relatively obvious that a >> > component's
> >> type == its model type. But what does it mean to >> specify >> >
> >> the type for a Panel, Link, WebMarkupContainer, etc. when you're
> >> >> not >> > even going to assign a model to the component (again,
> >> a fairly >> common >> > case)? I think classes that make sense as
> >> generics don't have this >> > problem -- they always hold, accept
> >> or return objects of their >> > specified type. >> > >> > A lot of
> >> this boils down to the fact that a component's type >> > parameter
> >> really has little to do with the component itself. >> It's for >>
> >> > the underlying model (including validation/conversion to the >>
> >> model's >> > object). Specifying the model's type in the component
> >> tightly >> couples >> > the two together, which clashes with
> >> Wicket's concept of models as >> > independent and dynamically
> >> resolvable objects (not to mention >> > clashing with MVC in
> >> general). >> > >> > So, I completely agree with everything you
> >> said below and just >> wanted >> > to throw out a "-1" for generic
> >> components hopefully before a final >> > decision is made. >> > >>
> >> > -Ryan >> > >> > >> > On Mar 6, 2007, at 9:57 PM, Eelco Hillenius
> >> wrote: >> > >> > > Hi, >> > > >> > > I think we went overboard
> >> applying generics in Wicket. >> > > >> > > Things like: >> > >
> >> TextField<Integer> integerTextField = new TextField<Integer> >>
> >> (this, >> > > "integerProperty", Integer.class); >> > > >> > > are
> >> just horrible imo. Sure, you can do: >> > > >> > > Integer i =
> >> integerTextField.getModelObject(); >> > > >> > > instead of: >> >
> >> > >> > > Integer i = (Integer)integerTextField.getModelObject();
> >> >> > > >> > > but that's about the whole great benefit of generic
> >> components >> for the >> > > price of about twice the verbosity.
> >> >> > > >> > > Also, calling getModelObject is the kind of
> >> convenience method >> that >> > > grew upon us but that I
> >> personally never liked. It saves an >> ugly model >> > > check,
> >> fine, but in general I think users should try to >> directly work
> >> >> > > with models and their underlying objects instead. >> > > >>
> >> > > I can see the method come in handy in list views (on >>
> >> ListItem), though >> > > then again, you know the model object
> >> would never be null >> there so >> > > getModel().getObject()
> >> would work as well. >> > > >> > > Anyway, what I'd like us to
> >> consider is to de-generify >> components and >> > > only keep it
> >> for models. For certain components (like >> ListView) we/ >> > >
> >> users can decide to introduce it, but the general case would >> be
> >> to not >> > > to. >> > > >> > > Thoughts? Screams? >> > > >> > >
> >> Eelco >> > >> > >>
> > -- Philip A. Chapman Desktop and Web Application Development:
> > Java, .NET, PostgreSQL, MySQL, MSSQL Linux, Windows 2000, Windows XP
>
>

Re: generics in Wicket

by Ryan Holmes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Mar 19, 2007, at 12:58 AM, Eelco Hillenius wrote:
>
> Do you have an idea that works without having to generify Component?
>

Not sure if you would put this in the "idea that works" category, but  
I was thinking of something like this:

public class Component {
        private IModel model;
       
        public <T> Component(final String id, final IModel<T> model) {
                this.model = model;
        }
       
        public <T> IModel<T> getModel() {
                return this.model;
        }
       
        public <T> void setModel(IModel<T> model) {
                this.model = model;
        }
}

This accommodates generic models but doesn't enforce type consistency  
between getModel and setModel. In practice, the types would usually  
be inferred:

IModel<Integer> model = component.getModel();

so it's easy to use and does eliminate casting, but get/set model  
inconsistency would only be caught at runtime (unless you use the  
full generic method syntax with a type parameter)

I don't know -- it doesn't really buy you much. This doesn't work:

Integer i = component.getModel().getObject();

I also played around with the idea of a generic "ModelHolder" object  
inside of Component so at least getModel() and setModel() would use  
the same type parameter, but again the get/set model methods on  
Component itself can't pick that type up.

<sigh> Oh well, maybe it's just taking me longer to come to the same  
conclusion you did.

-Ryan


RE: generics in Wicket

by Stefan Lindner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So the component developert must be very disciplined because the local variable "model" ist not generic. You can assign whatever IModel you want to the local "model". And the "return this.model" line will cause a warning.
 
In most cases it makes sense to have Generic components.
 
Stefan Lindner

________________________________

Von: Ryan Holmes [mailto:ryan@...]
Gesendet: Di 20.03.2007 07:58
An: wicket-dev@...
Betreff: Re: generics in Wicket




On Mar 19, 2007, at 12:58 AM, Eelco Hillenius wrote:
>
> Do you have an idea that works without having to generify Component?
>

Not sure if you would put this in the "idea that works" category, but
I was thinking of something like this:

public class Component {
        private IModel model;
       
        public <T> Component(final String id, final IModel<T> model) {
                this.model = model;
        }
       
        public <T> IModel<T> getModel() {
                return this.model;
        }
       
        public <T> void setModel(IModel<T> model) {
                this.model = model;
        }
}

This accommodates generic models but doesn't enforce type consistency
between getModel and setModel. In practice, the types would usually
be inferred:

IModel<Integer> model = component.getModel();

so it's easy to use and does eliminate casting, but get/set model
inconsistency would only be caught at runtime (unless you use the
full generic method syntax with a type parameter)

I don't know -- it doesn't really buy you much. This doesn't work:

Integer i = component.getModel().getObject();

I also played around with the idea of a generic "ModelHolder" object
inside of Component so at least getModel() and setModel() would use
the same type parameter, but again the get/set model methods on
Component itself can't pick that type up.

<sigh> Oh well, maybe it's just taking me longer to come to the same
conclusion you did.

-Ryan




Re: generics in Wicket

by Ryan Holmes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Mar 20, 2007, at 12:35 AM, Stefan Lindner wrote:

> So the component developert must be very disciplined because the  
> local variable "model" ist not generic. You can assign whatever  
> IModel you want to the local "model". And the "return this.model"  
> line will cause a warning.
The "return this.model" line is in the framework. The 2.0 code base  
is full of raw references to components which also cause warnings/
unchecked casts, so I don't think that's an issue. No argument on  
your bigger point that what I wrote below doesn't enforce type safety  
inside the component.
>
> In most cases it makes sense to have Generic components.
But that's what I'm having a hard time with (and maybe it's just  
because I haven't used 2.0) -- it seems like the majority of  
component instances don't benefit from being generic. You obviously  
use and like generic components quite a bit, so maybe you can give me  
some perspective. These are essentially the same questions I asked  
Philip:

When you have a form with a CompoundPropertyModel, do you still  
declare the type of the form components and, if so, why?

What about MarkupContainer components that you don't specify a model  
for?

-Ryan


>
> Stefan Lindner
>
> ________________________________
>
> Von: Ryan Holmes [mailto:ryan@...]
> Gesendet: Di 20.03.2007 07:58
> An: wicket-dev@...
> Betreff: Re: generics in Wicket
>
>
>
>
> On Mar 19, 2007, at 12:58 AM, Eelco Hillenius wrote:
>>
>> Do you have an idea that works without having to generify Component?
>>
>
> Not sure if you would put this in the "idea that works" category, but
> I was thinking of something like this:
>
> public class Component {
>         private IModel model;
>
>         public <T> Component(final String id, final IModel<T> model) {
>                 this.model = model;
>         }
>
>         public <T> IModel<T> getModel() {
>                 return this.model;
>         }
>
>         public <T> void setModel(IModel<T> model) {
>                 this.model = model;
>         }
> }
>
> This accommodates generic models but doesn't enforce type consistency
> between getModel and setModel. In practice, the types would usually
> be inferred:
>
> IModel<Integer> model = component.getModel();
>
> so it's easy to use and does eliminate casting, but get/set model
> inconsistency would only be caught at runtime (unless you use the
> full generic method syntax with a type parameter)
>
> I don't know -- it doesn't really buy you much. This doesn't work:
>
> Integer i = component.getModel().getObject();
>
> I also played around with the idea of a generic "ModelHolder" object
> inside of Component so at least getModel() and setModel() would use
> the same type parameter, but again the get/set model methods on
> Component itself can't pick that type up.
>
> <sigh> Oh well, maybe it's just taking me longer to come to the same
> conclusion you did.
>
> -Ryan
>
>
>


AW: generics in Wicket

by Stefan Lindner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In our applications, most components benefit from being generic. Even a Markupcontainer with custom components is used generic.
 
Stefan Lindner

________________________________

Von: Ryan Holmes [mailto:ryan@...]
Gesendet: Di 20.03.2007 08:56
An: wicket-dev@...
Betreff: Re: generics in Wicket




On Mar 20, 2007, at 12:35 AM, Stefan Lindner wrote:

> So the component developert must be very disciplined because the
> local variable "model" ist not generic. You can assign whatever
> IModel you want to the local "model". And the "return this.model"
> line will cause a warning.
The "return this.model" line is in the framework. The 2.0 code base
is full of raw references to components which also cause warnings/
unchecked casts, so I don't think that's an issue. No argument on
your bigger point that what I wrote below doesn't enforce type safety
inside the component.
>
> In most cases it makes sense to have Generic components.
But that's what I'm having a hard time with (and maybe it's just
because I haven't used 2.0) -- it seems like the majority of
component instances don't benefit from being generic. You obviously
use and like generic components quite a bit, so maybe you can give me
some perspective. These are essentially the same questions I asked
Philip:

When you have a form with a CompoundPropertyModel, do you still
declare the type of the form components and, if so, why?

What about MarkupContainer components that you don't specify a model
for?

-Ryan


>
> Stefan Lindner
>
> ________________________________
>
> Von: Ryan Holmes [mailto:ryan@...]
> Gesendet: Di 20.03.2007 07:58
> An: wicket-dev@...
> Betreff: Re: generics in Wicket
>
>
>
>
> On Mar 19, 2007, at 12:58 AM, Eelco Hillenius wrote:
>>
>> Do you have an idea that works without having to generify Component?
>>
>
> Not sure if you would put this in the "idea that works" category, but
> I was thinking of something like this:
>
> public class Component {
>         private IModel model;
>
>         public <T> Component(final String id, final IModel<T> model) {
>                 this.model = model;
>         }
>
>         public <T> IModel<T> getModel() {
>                 return this.model;
>         }
>
>         public <T> void setModel(IModel<T> model) {
>                 this.model = model;
>         }
> }
>
> This accommodates generic models but doesn't enforce type consistency
> between getModel and setModel. In practice, the types would usually
> be inferred:
>
> IModel<Integer> model = component.getModel();
>
> so it's easy to use and does eliminate casting, but get/set model
> inconsistency would only be caught at runtime (unless you use the
> full generic method syntax with a type parameter)
>
> I don't know -- it doesn't really buy you much. This doesn't work:
>
> Integer i = component.getModel().getObject();
>
> I also played around with the idea of a generic "ModelHolder" object
> inside of Component so at least getModel() and setModel() would use
> the same type parameter, but again the get/set model methods on
> Component itself can't pick that type up.
>
> <sigh> Oh well, maybe it's just taking me longer to come to the same
> conclusion you did.
>
> -Ryan
>
>
>



Re: generics in Wicket

by Philip A. Chapman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ryan,

I do not use property models much, so that's part of the difference between our points of view (our coding styles).  However, I do have at least one page that uses one.  In that case, I forgo generics.  I define raw types and set @SuppressWarnings("unchecked") on the methods that access them:

JTextField tf = new JTextField(this, "stringProperty");

I would like to make the point that when I do use PropertyModels, I usually throw away my component anyway (I don't usually assign it to a variable) because I only really care about the Model and the data in it anyway.  The above code snippet was just an example.

The @SuppressWarnings annotation tells the compiler to shut up and not bother me about it 'cause I know what I'm doing.  The case that I alluded to and Ivan asked about specifically is "What about those components where generics really does matter?"  Two components that he suggested really need generics are DropDownChoice and ListView.  There are others, but this raises a point.  I think that the problem that the wicket devs ran into early on is that either all components are generified or none (because of the models).

I think that my statement before is still a valid and is strengthened above.  If generic components are not appropriate for the code that you are writing, don't use them.  It's OK.  It's better for you to have a torx screwdriver in our common toolbox that you seldom use than to throw it out and I have non, but need it daily.

Thanks,

On Mon, 2007-03-19 at 22:03 -0700, Ryan Holmes wrote:
It's not that I don't like generics -- I just don't think Component  
makes sense as a generic class because it seems like the majority of  
use cases don't call for specifying a model type.

Let me ask you, do you specify the type for form components even when  
you're using a CompoundPropertyModel (i.e. when you're never going to  
call getModel() or getModelObject() directly on those components)?

And what about MarkupContainers and other components that you usually  
don't assign a model to?

-Ryan


On Mar 19, 2007, at 11:25 AM, Philip A. Chapman wrote:

> Guys,
>
> I've used generics with 2.0 at length, and absolutely love them.  I  
> am a huge fan of catching a problem early with compile-time errors  
> rather than finding out later that I'm returning the wrong type  
> from a model or that my Formatter is expecting a different type.   
> Yes, for a while the angle brackets are ugly and annoying.  Heck  
> the first time I saw C style language, I thought that all the  
> braces where ugly as sin.  When I first began using annotations, I  
> found it hard to read.  Now?  I've used all these things and have  
> learned how to read them without having to stare at them a long  
> time.  Now I can move on to using them to make my code better.
>
> You do not *have* to use generics even with a generified  
> framework.  You will have to do a lot of casting and get a lot of  
> compiler warnings, but it is not required.  Nothing keeps you from  
> defining a variable as a ListChoice rather than  
> ListChoice<MyUserBean>.  I, on the other hand use  
> ListChoice<MyUserBean> extensively.  To take that away would  
> require that I touch a lot of code.  For you, it requires that you  
> ignore compiler warnings.
>
> All in all, I don't care much about the constructor change, but I  
> consider generics to be a must-have.
>
> Anyway, that's my 2 cents.  Your mileage may vary, of course.
>
> On Sun, 2007-03-18 at 22:22 -0700, Ryan Holmes wrote:
>> Sure, but converters shouldn't necessarily be more tightly coupled  
>> to models either. Converters might use more fine grained types  
>> than a model, for instance (although I do see your point -- if  
>> objects are naturally tightly coupled there's no reason to pretend  
>> they're not). I guess I'm looking at this from a fundamentally  
>> different point of view: I've been getting by just fine with  
>> Wicket 1.2 (better than fine -- I freakin' love it) and haven't  
>> once been bothered by the lack of generics. I end up with maybe  
>> one or two casts in a page which just isn't a big deal. At the  
>> same time, generic components seem to add little and cost a lot in  
>> terms of productivity, readability and upgrade effort. So I  
>> totally agree that some things are nicer with generics. But that  
>> doesn't mean that generic components are the right design. I mean,  
>> are there demonstrable advantages to generic components that make  
>> Wicket a better framework and/or improve the API from a user's  
>> point of view? Or are generic components strictly a side-effect of  
>> generic models? -Ryan On Mar 18, 2007, at 6:35 PM, Igor Vaynberg  
>> wrote: > the thing is the model ties into a few places in the  
>> component > > for example IConverter Component.getConverter(). it  
>> would be nice > to say new > WebMarkupContainer<Person>  
>> { IConverter<Person> getConverter() {...}} > > things like that >  
>> > -igor > > > On 3/18/07, Eelco Hillenius  
>> <eelco.hillenius@...> wrote: >> >> Hi Ryan, >> >> The  
>> problem is - I found out later - that we can't really generify >>  
>> models in a meaningful way without generifying components as well.  
>> At >> least, I haven't found a good way. >> >> Do you have  
>> concrete suggestions or a proposal of how we could >> implement  
>> generics in a meaningful but non-obstrusive way? >> >> Eelco >> >>  
>> >> On 3/18/07, Ryan Holmes <ryan@...> wrote: >> > I  
>> think generic components are a mistake for several reasons. Not >>  
>> > only is the snippet below ugly and redundant, it doesn't even >>  
>> save a >> > cast if you're using a CompoundPropertyModel (which is  
>> the most >> > common case in my app). Well, I guess you save one  
>> cast, but that's >> > for the parent component's model, not for  
>> the form components >> > themselves. >> > >> > At least for  
>> FormComponents, it's relatively obvious that a >> > component's  
>> type == its model type. But what does it mean to >> specify >> >  
>> the type for a Panel, Link, WebMarkupContainer, etc. when you're  
>> >> not >> > even going to assign a model to the component (again,  
>> a fairly >> common >> > case)? I think classes that make sense as  
>> generics don't have this >> > problem -- they always hold, accept  
>> or return objects of their >> > specified type. >> > >> > A lot of  
>> this boils down to the fact that a component's type >> > parameter  
>> really has little to do with the component itself. >> It's for >>  
>> > the underlying model (including validation/conversion to the >>  
>> model's >> > object). Specifying the model's type in the component  
>> tightly >> couples >> > the two together, which clashes with  
>> Wicket's concept of models as >> > independent and dynamically  
>> resolvable objects (not to mention >> > clashing with MVC in  
>> general). >> > >> > So, I completely agree with everything you  
>> said below and just >> wanted >> > to throw out a "-1" for generic  
>> components hopefully before a final >> > decision is made. >> > >>  
>> > -Ryan >> > >> > >> > On Mar 6, 2007, at 9:57 PM, Eelco Hillenius  
>> wrote: >> > >> > > Hi, >> > > >> > > I think we went overboard  
>> applying generics in Wicket. >> > > >> > > Things like: >> > >  
>> TextField<Integer> integerTextField = new TextField<Integer> >>  
>> (this, >> > > "integerProperty", Integer.class); >> > > >> > > are  
>> just horrible imo. Sure, you can do: >> > > >> > > Integer i =  
>> integerTextField.getModelObject(); >> > > >> > > instead of: >> >  
>> > >> > > Integer i = (Integer)integerTextField.getModelObject();  
>> >> > > >> > > but that's about the whole great benefit of generic  
>> components >> for the >> > > price of about twice the verbosity.  
>> >> > > >> > > Also, calling getModelObject is the kind of  
>> convenience method >> that >> > > grew upon us but that I  
>> personally never liked. It saves an >> ugly model >> > > check,  
>> fine, but in general I think users should try to >> directly work  
>> >> > > with models and their underlying objects instead. >> > > >>  
>> > > I can see the method come in handy in list views (on >>  
>> ListItem), though >> > > then again, you know the model object  
>> would never be null >> there so >> > > getModel().getObject()  
>> would work as well. >> > > >> > > Anyway, what I'd like us to  
>> consider is to de-generify >> components and >> > > only keep it  
>> for models. For certain components (like >> ListView) we/ >> > >  
>> users can decide to introduce it, but the general case would >> be  
>> to not >> > > to. >> > > >> > > Thoughts? Screams? >> > > >> > >  
>> Eelco >> > >> > >>
> -- Philip A. Chapman Desktop and Web Application Development:  
> Java, .NET, PostgreSQL, MySQL, MSSQL Linux, Windows 2000, Windows XP

-- 
Philip A. Chapman

Desktop and Web Application Development:
Java, .NET, PostgreSQL, MySQL, MSSQL
Linux, Windows 2000, Windows XP


signature.asc (196 bytes) Download Attachment

Re: generics in Wicket

by Philip A. Chapman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2007-03-20 at 05:37 -0500, Philip A. Chapman wrote:

JTextField tf = new JTextField(this, "stringProperty");


JTextField???  Ok.  I've been doing too much swing lately.  Hopefully, you know that I ment TextField and not JTextField.  Sadly, the models in Swing are *much* more complicated and are not generified (as the components are not).

-- 
Philip A. Chapman

Desktop and Web Application Development:
Java, .NET, PostgreSQL, MySQL, MSSQL
Linux, Windows 2000, Windows XP


signature.asc (196 bytes) Download Attachment

Re: generics in Wicket

by Patrick Angeles :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Johan Compagner wrote:
no i am not pro for degenerifying it.
I like the getModelObject()

and that we have to do this:
 TextField<Integer> integerTextField = new
TextField<Integer>(this,"integerProperty", Integer.class);
I haven't looked at Wicket 2.0 source, so I may be off here, but it's possible to skip the last parameter of the TextField constructor so it looks like this:

TextField<Integer> integerTextField = new TextField<Integer>(this,"integerProperty") ;


Re: generics in Wicket

by Eelco Hillenius :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think it is. Limitation of how generics work I'm afraid.

Eelco

On 3/20/07, Patrick Angeles <patrick@...> wrote:

>
>
> Johan Compagner wrote:
> >
> > no i am not pro for degenerifying it.
> > I like the getModelObject()
> >
> > and that we have to do this:
> >  TextField<Integer> integerTextField = new
> > TextField<Integer>(this,"integerProperty", Integer.class);
> >
>
> I haven't looked at Wicket 2.0 source, so I may be off here, but it's
> possible to skip the last parameter of the TextField constructor so it looks
> like this:
>
> TextField<Integer> integerTextField = new
> TextField<Integer>(this,"integerProperty") ;
>
>
> --
> View this message in context: http://www.nabble.com/generics-in-Wicket-tf3360271.html#a9580850
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>

Re: generics in Wicket

by Patrick Angeles :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yea... come to think of it... the generic type gets erased at runtime.

Eelco Hillenius wrote:
I don't think it is. Limitation of how generics work I'm afraid.

Eelco

On 3/20/07, Patrick Angeles <patrick@inertiabev.com> wrote:
>
>
> Johan Compagner wrote:
> >
> > no i am not pro for degenerifying it.
> > I like the getModelObject()
> >
> > and that we have to do this:
> >  TextField<Integer> integerTextField = new
> > TextField<Integer>(this,"integerProperty", Integer.class);
> >
>
> I haven't looked at Wicket 2.0 source, so I may be off here, but it's
> possible to skip the last parameter of the TextField constructor so it looks
> like this:
>
> TextField<Integer> integerTextField = new
> TextField<Integer>(this,"integerProperty") ;
>
>
> --
> View this message in context: http://www.nabble.com/generics-in-Wicket-tf3360271.html#a9580850
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>

Re: generics in Wicket

by Ryan Holmes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure what IModel<T> is for in that ListView constructor, but  
the IModel<List<T>> is nice.

About the DropDownChoice, while the clarity is improved there as  
well, that constructor prevents superclass/subclass type combinations  
that should be legal.

For example, given the canonical Employee and Manager classes where  
Manager is a subclass of Employee, the following code won't compile:
       
        // Service method that returns only managers
        public List<Manager> getManagers() {
                ...
        }
       
        // An entity object that holds an employee reference
        public class Company {
                private Employee employee;
               
                public Employee getEmployee() {
                        return this.employee;
                }
        }

        // DropDownChoice declaration that won't compile
        public void test() {
                Company company = new Company();
                Model<List<Manager>> managers = new Model<List<Manager>>(getManagers
());
                DropDownChoice<Employee> choice = new DropDownChoice<Employee>("id",
                                new Model<Employee>(company.getEmployee()), managers, new  
ChoiceRenderer<Employee>());
        }


I don't think this example is too unusual. The types could be  
dictated by existing code: the service method returns a specific  
subclass and the entity takes a superclass. We have a lot of  
combinations like this because we have some pretty deep class  
hierarchies.

Another problem would be a DropDownChoice<Manager> with a  
ChoiceRenderer<Employee>, which again doesn't seem too unusual (and  
we have that situation as well).

Unless my generics-fu is simply not up to snuff, it looks like there  
could be some real technical issues with generic components in  
addition to readability and productivity problems with all the time  
and characters spent declaring types.

This is kind of half-assed, but I think the same level of clarity  
improvement in those constructors could be achieved with:

ListView(String,IModel,IModel<List>)

and

DropDownChoice(String,IModel,IModel<List>,IChoiceRenderer)

-Ryan

On Mar 19, 2007, at 10:21 PM, Igor Vaynberg wrote:

> what about the cases where it is very nice to have?
>
> ListView(String,IModel<T>,IModel<List<T>>)
>
> or
>
> DropDownChoice(String,IModel<T>,IModel<List<T>>,IChoiceRenderer<T>)
>
> im not arguing for or against, but there are cases where it is very  
> nice to
> have them, especially for newbies. when a newbie looks at the above  
> they
> know whats going on as opposed to
>
> DropDownChoice(String,IModel,IModel,IChoiceRenderer)
>
> -igor
>
>


Re: generics in Wicket

by Ryan Holmes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the feedback Philip.

I use property models, especially CompoundPropertyModel, extensively  
and wouldn't consider using a framework that didn't have good support  
for property binding. It saves a huge amount of development time.

The reason I don't think it's sufficient to say "use  
@SuppressWarnings" is because 1) a well-designed framework shouldn't  
require you to suppress compiler warnings in the first place (at  
least not very often) and 2) unless I'm going to apply that  
annotation on an almost line-by-line basis, it can hide warnings that  
I want to see.

We've been using generics at my work for quite a while now, written a  
lot of generic classes, etc. and only have a handful of  
@SuppressWarnings("unchecked") annotations. If you look at how/where  
generics have been applied in the JDK, they tend to be on classes  
that do little more than hold and operate on objects of their  
declared type or are otherwise naturally strongly associated with  
that type. Therefore, there's rarely a need to use the raw versions  
of those classes.

Component, on the other hand, mostly consists of methods that do not  
use the declared type and I think typical usage (which probably  
involves a lot of property models and markup containers) leads to a  
majority of Component instances deriving no benefit from specifying a  
model type.

I don't think your tool analogy holds up here, because generics don't  
add any new functionality. There's nothing you can do with generics  
that you can't do without them.

Unfortunately, I think like/dislike of generics in Wicket is largely  
a matter of style. It's tough to come up with quantitative points for  
or against.

-Ryan

On Mar 20, 2007, at 3:37 AM, Philip A. Chapman wrote:

> Ryan,
>
> I do not use property models much, so that's part of the difference  
> between our points of view (our coding styles).  However, I do have  
> at least one page that uses one.  In that case, I forgo generics.  
> I define raw types and set @SuppressWarnings("unchecked") on the  
> methods that access them:
>
> JTextField tf = new JTextField(this, "stringProperty");
>
> I would like to make the point that when I do use PropertyModels, I  
> usually throw away my component anyway (I don't usually assign it  
> to a variable) because I only really care about the Model and the  
> data in it anyway.  The above code snippet was just an example.
>
> The @SuppressWarnings annotation tells the compiler to shut up and  
> not bother me about it 'cause I know what I'm doing.  The case that  
> I alluded to and Ivan asked about specifically is "What about those  
> components where generics really does matter?"  Two components that  
> he suggested really need generics are DropDownChoice and ListView.  
> There are others, but this raises a point.  I think that the  
> problem that the wicket devs ran into early on is that either all  
> components are generified or none (because of the models).
>
> I think that my statement before is still a valid and is  
> strengthened above.  If generic components are not appropriate for  
> the code that you are writing, don't use them.  It's OK.  It's  
> better for you to have a torx screwdriver in our common toolbox  
> that you seldom use than to throw it out and I have non, but need  
> it daily.
>
> Thanks,
>
> On Mon, 2007-03-19 at 22:03 -0700, Ryan Holmes wrote:
>> It's not that I don't like generics -- I just don't think  
>> Component makes sense as a generic class because it seems like the  
>> majority of use cases don't call for specifying a model type. Let  
>> me ask you, do you specify the type for form components even when  
>> you're using a CompoundPropertyModel (i.e. when you're never going  
>> to call getModel() or getModelObject() directly on those  
>> components)? And what about MarkupContainers and other components  
>> that you usually don't assign a model to? -Ryan On Mar 19, 2007,  
>> at 11:25 AM, Philip A. Chapman wrote: > Guys, > > I've used  
>> generics with 2.0 at length, and absolutely love them. I > am a  
>> huge fan of catching a problem early with compile-time errors >  
>> rather than finding out later that I'm returning the wrong type >  
>> from a model or that my Formatter is expecting a different type. >  
>> Yes, for a while the angle brackets are ugly and annoying. Heck >  
>> the first time I saw C style language, I thought that all the >  
>> braces where ugly as sin. When I first began using annotations, I  
>> > found it hard to read. Now? I've used all these things and have  
>> > learned how to read them without having to stare at them a long  
>> > time. Now I can move on to using them to make my code better. >  
>> > You do not *have* to use generics even with a generified >  
>> framework. You will have to do a lot of casting and get a lot of >  
>> compiler warnings, but it is not required. Nothing keeps you from  
>> > defining a variable as a ListChoice rather than >  
>> ListChoice<MyUserBean>. I, on the other hand use >  
>> ListChoice<MyUserBean> extensively. To take that away would >  
>> require that I touch a lot of code. For you, it requires that you  
>> > ignore compiler warnings. > > All in all, I don't care much  
>> about the constructor change, but I   > consider generics to be a  
>> must-have. > > Anyway, that's my 2 cents. Your mileage may vary,  
>> of course. > > On Sun, 2007-03-18 at 22:22 -0700, Ryan Holmes  
>> wrote: >> Sure, but converters shouldn't necessarily be more  
>> tightly coupled >> to models either. Converters might use more  
>> fine grained types >> than a model, for instance (although I do  
>> see your point -- if >> objects are naturally tightly coupled  
>> there's no reason to pretend >> they're not). I guess I'm looking  
>> at this from a fundamentally >> different point of view: I've been  
>> getting by just fine with >> Wicket 1.2 (better than fine -- I  
>> freakin' love it) and haven't >> once been bothered by the lack of  
>> generics. I end up with maybe >> one or two casts in a page which  
>> just isn't a big deal. At the >> same time, generic components  
>> seem to add little and cost a lot in >> terms of productivity,  
>> readability and upgrade effort. So I >> totally agree that some  
>> things are nicer with generics. But that >> doesn't mean that  
>> generic components are the right design. I mean, >> are there  
>> demonstrable advantages to generic components that make >> Wicket  
>> a better framework and/or improve the API from a user's >> point  
>> of view? Or are generic components strictly a side-effect of >>  
>> generic models? -Ryan On Mar 18, 2007, at 6:35 PM, Igor Vaynberg  
>> >> wrote: > the thing is the model ties into a few places in the  
>> >> component > > for example IConverter Component.getConverter().  
>> it >> would be nice > to say new > WebMarkupContainer<Person> >>  
>> { IConverter<Person> getConverter() {...}} > > things like that >  
>> >> > -igor > > > On 3/18/07, Eelco Hillenius >>  
>> <eelco.hillenius@...> wrote: >> >> Hi Ryan, >> >> The >>  
>> problem is - I found out later - that we can't really generify >>  
>> >> models in a meaningful way without generifying components as  
>> well. >> At >> least, I haven't found a good way. >> >> Do you  
>> have >> concrete suggestions or a proposal of how we could >>  
>> implement >> generics in a meaningful but non-obstrusive way? >>  
>> >> Eelco >> >> >> >> On 3/18/07, Ryan Holmes <ryan@...>  
>> wrote: >> > I >> think generic components are a mistake for  
>> several reasons. Not >> >> > only is the snippet below ugly and  
>> redundant, it doesn't even >> >> save a >> > cast if you're using  
>> a CompoundPropertyModel (which is >> the most >> > common case in  
>> my app). Well, I guess you save one >> cast, but that's >> > for  
>> the parent component's model, not for >> the form components >> >  
>> themselves. >> > >> > At least for >> FormComponents, it's  
>> relatively obvious that a >> > component's >> type == its model  
>> type. But what does it mean to >> specify >> > >> the type for a  
>> Panel, Link, WebMarkupContainer, etc. when you're >> >> not >> >  
>> even going to assign a model to the component (again, >> a fairly  
>> >> common >> > case)? I think classes that make sense as >>  
>> generics don't have this >> > problem -- they always hold, accept  
>> >> or return objects of their >> > specified type. >> > >> > A lot  
>> of >> this boils down to the fact that a component's type >> >  
>> parameter >> really has little to do with the component itself. >>  
>> It's for >> >> > the underlying model (including validation/
>> conversion to the >> >> model's >> > object). Specifying the  
>> model's type in the component >> tightly >> couples >> > the two  
>> together, which clashes with >> Wicket's concept of models as >> >  
>> independent and dynamically >> resolvable objects (not to mention  
>> >> > clashing with MVC in >> general). >> > >> > So, I completely  
>> agree with everything you >> said below and just >> wanted >> > to  
>> throw out a "-1" for generic >> components hopefully before a  
>> final >> > decision is made. >> > >> >> > -Ryan >> > >> > >> > On  
>> Mar 6, 2007, at 9:57 PM, Eelco Hillenius >> wrote: >> > >> > > Hi,  
>> >> > > >> > > I think we went overboard >> applying generics in  
>> Wicket. >> > > >> > > Things like: >> > > >> TextField<Integer>  
>> integerTextField = new TextField<Integer> >> >> (this, >> > >  
>> "integerProperty", Integer.class); >> > > >> > > are >> just  
>> horrible imo. Sure, you can do: >> > > >> > > Integer i = >>  
>> integerTextField.getModelObject(); >> > > >> > > instead of: >> >  
>> >> > >> > > Integer i = (Integer)integerTextField.getModelObject
>> (); >> >> > > >> > > but that's about the whole great benefit of  
>> generic >> components >> for the >> > > price of about twice the  
>> verbosity. >> >> > > >> > > Also, calling getModelObject is the  
>> kind of >> convenience method >> that >> > > grew upon us but that  
>> I >> personally never liked. It saves an >> ugly model >> > >  
>> check, >> fine, but in general I think users should try to >>  
>> directly work >> >> > > with models and their underlying objects  
>> instead. >> > > >> >> > > I can see the method come in handy in  
>> list views (on >> >> ListItem), though >> > > then again, you know  
>> the model object >> would never be null >> there so >> > > getModel
>> ().getObject() >> would work as well. >> > > >> > > Anyway, what  
>> I'd like us to >> consider is to de-generify >> components and >>  
>> > > only keep it >> for models. For certain components (like >>  
>> ListView) we/ >> > > >> users can decide to introduce it, but the  
>> general case would >> be >> to not >> > > to. >> > > >> > >  
>> Thoughts? Screams? >> > > >> > > >> Eelco >> > >> > >> > -- Philip  
>> A. Chapman Desktop and Web Application Development: > Java, .NET,  
>> PostgreSQL, MySQL, MSSQL Linux, Windows 2000, Windows XP
> -- Philip A. Chapman Desktop and Web Application Development:  
> Java, .NET, PostgreSQL, MySQL, MSSQL Linux, Windows 2000, Windows XP

< Prev | 1 - 2 - 3 | Next >