Please read up on models.  You don't understand why they're needed.  You
need them as a location service for data so that components don't have to
know where the data comes from.  In this way, the data can come from the
session or the db, etc.  Also, when a link on the page modifies something,
your constructor will not be called again, which means that your components
will all have the old, unmodified version of the data and won't show the
latest data.  Whereas, if you used a model, they would call getObject()
which would get the latest version of the data, from, for instance, the
database.

See this page for more on models:
http://cwiki.apache.org/WICKET/working-with-wicket-models.html

See this post to see an example:
http://www.mail-archive.com/[email protected]/msg42352.html


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



On Tue, Oct 6, 2009 at 2:36 AM, Robin Sander <[email protected]> wrote:

>
> Ok, I overlooked that IModel extends IDetachable but besides the detach()
> method
> - which would be a special model behaviour in my opinion - IModel does have
> two
> methods only:
>
>        T getObject();
>        void setObject(final T object);
>
> Where's the benefit of using
>  new Component<MyBean>("xy", new Model<MyBean>(myBean))
> and then access the actual model (object) by using getObject()/setObject()
> instead of
>  new Component<MyBean>("xy", myBean)
> and then having a field
>  T model;
> which could be directly accessed? (or even wrapped if you want to implement
> additional
> stuff)
>
> A user may add still addional behaviour by implementing special interfaces
> like Detachable
> or something. This approach looks more natural for me but I'm asking more
> out of curiosity...
>
>
> On Oct 5, 2009, at 18:32, Jeremy Thomerson wrote:
>
>  On Mon, Oct 5, 2009 at 7:44 AM, Robin Sander <[email protected]>
>> wrote:
>>
>>  Another question because someone mentioned it in this thread and I asked
>>> this question myself:
>>> why do we need an empty interface for Model? Why can't a mere String or
>>> any
>>> serializable POJO be
>>> used as a model? (than this discussion about the name would end also...)
>>>
>>>
>> I'm not sure I understand what you're saying.  IModel is currently the
>> interface and is not an empty interface.  And an instance of IModel is a
>> data proxy / location service - not the actual data itself - which is whay
>> any POJO can not be a model.  The POJO is the model object.
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>
>

Reply via email to