You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mike Dee <md...@cardeatech.com> on 2010/08/27 14:37:11 UTC

Question about Wicket and generics

Coming up to speed in Wicket and see some things that I don't know how to
interpret regarding generics.

First, I have a form subclass that looks like this:

    private class MyForm extends Form

Eclipse shows the following warning:

    Form is a raw type. References to generic type Form<T> should be
parameterized.

I'd like to try and understand this.  What could <T> possibly be?

Second, for some things, I'm questioning my understanding of either generics
or Wicket.  Example:
    
    TextField<String> foo = new TextField<String>( "foo", model );

But isn't "TextField" implying text (or a string).  Would TextField<Integer>
make sense (haven't tried it yet)?  If it makes sense, then maybe TextField
is just a bad name and TextField should be thought of as "Field"?

Just trying to get a grasp on generics in Wicket.  Maybe my grasp on
generics isn't so hot either.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341004.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: Question about Wicket and generics

Posted by James Carman <ja...@carmanconsulting.com>.
On Fri, Aug 27, 2010 at 8:37 AM, Mike Dee <md...@cardeatech.com> wrote:
>
> I'd like to try and understand this.  What could <T> possibly be?
>

It would be whatever your form is "editing."

> But isn't "TextField" implying text (or a string).  Would TextField<Integer>
> make sense (haven't tried it yet)?  If it makes sense, then maybe TextField
> is just a bad name and TextField should be thought of as "Field"?
>

You can have TextField<Integer>, yes.  Wicket uses Converters to
support converting to/from the type needed.

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


Re: Question about Wicket and generics

Posted by Mike Dee <md...@cardeatech.com>.
Great, didn't know there was a built in LoginForm.

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341060.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: Question about Wicket and generics

Posted by James Carman <ja...@carmanconsulting.com>.
You could use Void for that or just use the built-in login form
support that comes with Wicket! :)


On Fri, Aug 27, 2010 at 8:58 AM, Mike Dee <md...@cardeatech.com> wrote:
>
> Makes sense.  What is the recommended practice when a form is not tied to a
> class that encapsulates the model?  For example, picture a login screen that
> simply capture username and password strings.
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341026.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: Question about Wicket and generics

Posted by Mike Dee <md...@cardeatech.com>.
Makes sense.  What is the recommended practice when a form is not tied to a
class that encapsulates the model?  For example, picture a login screen that
simply capture username and password strings.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341026.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: Question about Wicket and generics

Posted by Igor Vaynberg <ig...@gmail.com>.
just offering the other side of the coin...i didnt say we were going
to yank the generics from the Form, chill :)

-igor

On Fri, Aug 27, 2010 at 8:38 AM, James Carman
<ja...@carmanconsulting.com> wrote:
> On Fri, Aug 27, 2010 at 11:34 AM, Igor Vaynberg <ig...@gmail.com> wrote:
>> i have written plenty forms and about 99% of them have Form<Void>.
>> models on the form are just not that useful, its the fields  that
>> care.
>
> That doesn't mean that's the way *everyone* uses them.  Then again, my
> way isn't necessarily the way everyone uses them either.  That's the
> great thing about Wicket.  It's flexible enough to let you skin your
> cat in any way you like.
>
> ---------------------------------------------------------------------
> 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: Question about Wicket and generics

Posted by James Carman <ja...@carmanconsulting.com>.
On Fri, Aug 27, 2010 at 11:34 AM, Igor Vaynberg <ig...@gmail.com> wrote:
> i have written plenty forms and about 99% of them have Form<Void>.
> models on the form are just not that useful, its the fields  that
> care.

That doesn't mean that's the way *everyone* uses them.  Then again, my
way isn't necessarily the way everyone uses them either.  That's the
great thing about Wicket.  It's flexible enough to let you skin your
cat in any way you like.

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


Re: Question about Wicket and generics

Posted by James Carman <ja...@carmanconsulting.com>.
On Fri, Aug 27, 2010 at 11:41 AM, Mike Dee <md...@cardeatech.com> wrote:
>
> In my experience, there are lots of other situations too.  For example, we
> have lots of forms for doing searches.  The form gathers the search
> criteria.  Maybe it would make sense to have a SearchFormCriteria class,
> which would be the model?  How are others doing this?
>

We do exactly that!  It helps in the case where you need to add
parameters to the search criteria.  You don't have to change your
method signatures in your repository/dao.  It just accepts
MySearchCriteria (or whatever you want to call it).  Then, you have a
Form<MySearchCriteria> which edits it.

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


Re: Question about Wicket and generics

Posted by Mike Dee <md...@cardeatech.com>.
Trying to understand if there is a pattern here or at least a common way
advanced Wicket users program.  I can see case where the Form may represent
an item in the database and it makes sense to have a corresponding model. 
Is that a Wicket pattern?  This would kind of be like the EJB in J2EE, where
the data item is the entity (and that could be the model).

In my experience, there are lots of other situations too.  For example, we
have lots of forms for doing searches.  The form gathers the search
criteria.  Maybe it would make sense to have a SearchFormCriteria class,
which would be the model?  How are others doing this?

Mike

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341288.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: Question about Wicket and generics

Posted by Igor Vaynberg <ig...@gmail.com>.
i have written plenty forms and about 99% of them have Form<Void>.
models on the form are just not that useful, its the fields  that
care.

-igor

On Fri, Aug 27, 2010 at 5:45 AM, James Carman
<ja...@carmanconsulting.com> wrote:
> On Fri, Aug 27, 2010 at 8:40 AM, Mike Dee <md...@cardeatech.com> wrote:
>>
>> Also noticed in prior messages with similar topic that someone suggested
>> using "Void" (Form<Void>).  Never knew there was a Void keyword (capital V).
>> Is this a recommended technique for  Form (ie. Form<Void>)?
>
> It's certainly possible.  Remember that the type of model that the
> form uses would need to be a Model<Void>, though.  For the most part,
> your form is going to be modifying something, so it's just easier to
> base your form on that type.  So, you'd have, for example:
>
> IModel<Person> model = ...;
> Form<Person> personForm = new Form<Person>("personForm", model);
> personForm.add(new TextField<String>("firstName", new
> PropertyModel<String>(model, "firstName"));
>
> ---------------------------------------------------------------------
> 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: Question about Wicket and generics

Posted by James Carman <ja...@carmanconsulting.com>.
On Fri, Aug 27, 2010 at 8:40 AM, Mike Dee <md...@cardeatech.com> wrote:
>
> Also noticed in prior messages with similar topic that someone suggested
> using "Void" (Form<Void>).  Never knew there was a Void keyword (capital V).
> Is this a recommended technique for  Form (ie. Form<Void>)?

It's certainly possible.  Remember that the type of model that the
form uses would need to be a Model<Void>, though.  For the most part,
your form is going to be modifying something, so it's just easier to
base your form on that type.  So, you'd have, for example:

IModel<Person> model = ...;
Form<Person> personForm = new Form<Person>("personForm", model);
personForm.add(new TextField<String>("firstName", new
PropertyModel<String>(model, "firstName"));

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


Re: Question about Wicket and generics

Posted by Mike Dee <md...@cardeatech.com>.
Also noticed in prior messages with similar topic that someone suggested
using "Void" (Form<Void>).  Never knew there was a Void keyword (capital V). 
Is this a recommended technique for  Form (ie. Form<Void>)?
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341007.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: Question about Wicket and generics

Posted by Mike Dee <md...@cardeatech.com>.
Does that mean that somewhere (probably internal to Wicket), there is some
place that does something like this: 

    X x = MyForm<X>;

Still having difficulty seeing a case where it is useful to have a situation
that with not Form<Void>.  Would like to hear about such a situation.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-about-Wicket-and-generics-tp2341004p2341500.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