It does, thank you. But in your example, won't the model object be a
list, not the actual object? And if it is the object, wouldn't it be
the wrong object if the underlying datastore had changed between
requests?

-Phil

On 6/19/05, Martijn Dashorst <[EMAIL PROTECTED]> wrote:
> Phil Kulak wrote:
> 
> >So, as long as I don't make something final, am I alright?
> >
> That was not what I meant. When you make things final, you keep
> references to those objects. You can make things final, but you /really/
> need to know what will happen then.
> 
> >For
> >example, how about not using an inner class:
> >
> >final PageableListView list = new PageableListView("rows", data, 10)
> >{
> >   public void populateItem(ListItem listItem)
> >      {
> >            MyObject value = (MyObject) listItem.getModelObject();
> >            listItem.add(new Label("name", value.getName()));
> >      }
> >};
> >
> >It looks to me here like the reference to the "name" String will live
> >on between requests, but that the object itself and all other
> >properties should get garbage collected. Is that right?
> >
> >
> True, but that was not your question. You tried to use one instance of
> an object both at render time and when the request is processed.
> The problem /may/ arrize when you have different moments of refering to
> the objects (i.e. storing references to them during render time and
> using those when the request gets handled) or when you use
> REDIRECT_TO_RENDER. Using Hibernate you may experience objects that
> aren't attached to a Hibernate session.
> 
> If you keep a 'hard' reference to the objects, they won't get attached
> when handling the request. So you have to use the getModelObject()
> method to retrieve the object. This will attach the model, and give you
> the correct object (fresh from the database).
> 
> I hope I make some sense to you.
> 
> Martijn
> 
> >On 6/19/05, Martijn Dashorst <[EMAIL PROTECTED]> wrote:
> >
> >
> >>The problem is that populateItem() is called at render time, and that
> >>the onClick() is called when you have been to the client and are
> >>processing the component listener. I have falled into this trap myself,
> >>and I can only advise you to use the following code, which is a lot more
> >>safer in any context:
> >>
> >>final PageableListView list = new PageableListView("rows", data, 10)
> >>{
> >>    public void populateItem(ListItem listItem)
> >>       {
> >>          listItem.add(new Link("sjs") {
> >>             public void onClick() {
> >>                MyObject value = (MyObject) getParent().getModelObject();
> >>                System.out.println(value.getName());
> >>             }
> >>       }
> >>};
> >>
> >>Note that all final keywords have disappeared and no hidden magic is
> >>remaining on keeping references to object between render and handling time.
> >>
> >>Martijn
> >>
> >>
> >>Phil Kulak wrote:
> >>
> >>
> >>
> >>>Maybe it's just late, but I can't seem to answer this question myself.
> >>>Will each model object in my list exist after the request has finished
> >>>with the following code, assuming that the list is wrapped in a
> >>>detachable model:
> >>>
> >>>final PageableListView list = new PageableListView("rows", data, 10)
> >>>{
> >>>       public void populateItem(final ListItem listItem)
> >>>       {
> >>>                final MyObject value = (MyObject) 
> >>> listItem.getModelObject();
> >>>                listItem.add(new Link("sjs") {
> >>>                              public void onClick() {
> >>>                                       System.out.println(value.getName());
> >>>                              }
> >>>                });
> >>>       }
> >>>};
> >>>
> >>>or how about this:
> >>>
> >>>final PageableListView list = new PageableListView("rows", data, 10)
> >>>{
> >>>       public void populateItem(final ListItem listItem)
> >>>       {
> >>>                final MyObject value = (MyObject) 
> >>> listItem.getModelObject();
> >>>                final String name = value.getName();
> >>>
> >>>                listItem.add(new Link("sjs") {
> >>>                              public void onClick() {
> >>>                                       System.out.println(name);
> >>>                              }
> >>>                });
> >>>       }
> >>>};
> >>>
> >>>
> >>>------------------------------------ -------------------
> >>>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> >>>
> >>>
> >>>from IBM. Find simple to follow Roadmaps, straightforward articles,
> >>
> >>
> >>>informative Webcasts and more! Get everything you need to get up to
> >>>speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
> >>>_______________________________________________
> >>>Wicket-user mailing list
> >>>[email protected]
> >>>https://lists.sourceforge.net/lists/listinfo/wicket-user
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>-------------------------------------------------------
> >>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> >>from IBM. Find simple to follow Roadmaps, straightforward articles,
> >>informative Webcasts and more! Get everything you need to get up to
> >>speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> >>_______________________________________________
> >>Wicket-user mailing list
> >>[email protected]
> >>https://lists.sourceforge.net/lists/listinfo/wicket-user
> >>
> >>
> >>
> >
> >
> >-------------------------------------------------------
> >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> >from IBM. Find simple to follow Roadmaps, straightforward articles,
> >informative Webcasts and more! Get everything you need to get up to
> >speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
> >_______________________________________________
> >Wicket-user mailing list
> >[email protected]
> >https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
> >
> 
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to