You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bas Gooren <ba...@iswd.nl> on 2009/08/26 21:29:14 UTC

How to detect model "leakage" into session

Hi all,

My problem is as follows: I use LoadableDetachableModels throughout my application, and have made sure I never use a model without it being attached to a component to prevent models which never get their detach() method called.
Nonetheless, after hitting two fairly simple pages which list some database data in my application, I get a 100kb session which is filled with literal strings from model objects.

I've fired up my (Eclipse) debugger and have stepped through all models on one of the pages after setting a breakpoint on the pages onDetach() method. I see all LoadableDetachableModels are detached, so I have no idea what's causing this.

What would be a good strategy for finding the source of this problem?

Bas

Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Scott,

That's what I thought.

Bas

----- Original Message ----- 
From: "Scott Swank" <sc...@gmail.com>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 26, 2009 10:53 PM
Subject: Re: How to detect model "leakage" into session


> Bas,
>
> The code you showed is fine, foo will be garbage collected.  You only
> have to worry about situations where you reference a final object
> inside an anonymous inner class.  E.g. The below WebMarkupContainer
> can has to keep a reference to foo, and so foo cannot be garbage
> collected.
>
> final Foo foo = getModelObject();
>
> WebMarkupContainer bigBox = new WebMarkupContainer("me"){
> if( foo.getX() )
>  add( new Label("x", new PropertyModel( getModel(), "x" ) );
> else
>  add( new Label("x", new PropertyModel( getModel(), "y" ) );
> };
> add(bigBox);
>
> Scott
>
>
> Any time you make an object final it is potentially bound into the context 
> of
> On Wed, Aug 26, 2009 at 1:27 PM, Bas Gooren<ba...@iswd.nl> wrote:
>> Michael,
>>
>> This is something which is helpful in case you have models which are not
>> "owned" by a component. This is not the case in my application.
>> Also, the strategy they explain in the blog is something which is quite
>> common with wicket, at least for me: a model referencing another model, 
>> and
>> calling it's detach() method when its own onDetach() is called.
>>
>> Thanks anyway!
>>
>> Bas
>>
>> ----- Original Message ----- From: "Michael Mosmann" <mi...@mosmann.de>
>> To: <us...@wicket.apache.org>
>> Sent: Wednesday, August 26, 2009 10:13 PM
>> Subject: Re: How to detect model "leakage" into session
>>
>>
>>> Am Mittwoch, den 26.08.2009, 21:29 +0200 schrieb Bas Gooren:
>>>>
>>>> Hi all,
>>>>
>>>> My problem is as follows: I use LoadableDetachableModels throughout my
>>>> application, and have made sure I never use a model without it being
>>>> attached to a component to prevent models which never get their 
>>>> detach()
>>>> method called.
>>>> Nonetheless, after hitting two fairly simple pages which list some
>>>> database data in my application, I get a 100kb session which is filled 
>>>> with
>>>> literal strings from model objects.
>>>>
>>>> I've fired up my (Eclipse) debugger and have stepped through all models
>>>> on one of the pages after setting a breakpoint on the pages onDetach()
>>>> method. I see all LoadableDetachableModels are detached, so I have no 
>>>> idea
>>>> what's causing this.
>>>>
>>>> What would be a good strategy for finding the source of this problem?
>>>
>>> IMHO this could be a solution to your problem:
>>>
>>> http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/
>>>
>>> CascadingLoadableDetachableModel will detach it's child so that for any
>>> used model detach will be called.
>>>
>>> mm:)
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
> ---------------------------------------------------------------------
> 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: How to detect model "leakage" into session

Posted by Scott Swank <sc...@gmail.com>.
Bas,

The code you showed is fine, foo will be garbage collected.  You only
have to worry about situations where you reference a final object
inside an anonymous inner class.  E.g. The below WebMarkupContainer
can has to keep a reference to foo, and so foo cannot be garbage
collected.

final Foo foo = getModelObject();

WebMarkupContainer bigBox = new WebMarkupContainer("me"){
if( foo.getX() )
  add( new Label("x", new PropertyModel( getModel(), "x" ) );
else
  add( new Label("x", new PropertyModel( getModel(), "y" ) );
};
add(bigBox);

Scott


Any time you make an object final it is potentially bound into the context of
On Wed, Aug 26, 2009 at 1:27 PM, Bas Gooren<ba...@iswd.nl> wrote:
> Michael,
>
> This is something which is helpful in case you have models which are not
> "owned" by a component. This is not the case in my application.
> Also, the strategy they explain in the blog is something which is quite
> common with wicket, at least for me: a model referencing another model, and
> calling it's detach() method when its own onDetach() is called.
>
> Thanks anyway!
>
> Bas
>
> ----- Original Message ----- From: "Michael Mosmann" <mi...@mosmann.de>
> To: <us...@wicket.apache.org>
> Sent: Wednesday, August 26, 2009 10:13 PM
> Subject: Re: How to detect model "leakage" into session
>
>
>> Am Mittwoch, den 26.08.2009, 21:29 +0200 schrieb Bas Gooren:
>>>
>>> Hi all,
>>>
>>> My problem is as follows: I use LoadableDetachableModels throughout my
>>> application, and have made sure I never use a model without it being
>>> attached to a component to prevent models which never get their detach()
>>> method called.
>>> Nonetheless, after hitting two fairly simple pages which list some
>>> database data in my application, I get a 100kb session which is filled with
>>> literal strings from model objects.
>>>
>>> I've fired up my (Eclipse) debugger and have stepped through all models
>>> on one of the pages after setting a breakpoint on the pages onDetach()
>>> method. I see all LoadableDetachableModels are detached, so I have no idea
>>> what's causing this.
>>>
>>> What would be a good strategy for finding the source of this problem?
>>
>> IMHO this could be a solution to your problem:
>>
>> http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/
>>
>> CascadingLoadableDetachableModel will detach it's child so that for any
>> used model detach will be called.
>>
>> mm:)
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Ok, I found the source of the problem ;-)

I must've hit enter a little too quick on a content-complete in Eclipse.
Inside one of the repeaters on the page I had

new PropertyModel( item.getModelObject(), "x" )

instead of

new PropertyModel( item.getModel(), "x" )

Obviously that's going to increase session size as it's a direct reference 
to an object.

Thanks for giving me some pointers!

Bas

----- Original Message ----- 
From: "Bas Gooren" <ba...@iswd.nl>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 26, 2009 10:27 PM
Subject: Re: How to detect model "leakage" into session


> Michael,
>
> This is something which is helpful in case you have models which are not 
> "owned" by a component. This is not the case in my application.
> Also, the strategy they explain in the blog is something which is quite 
> common with wicket, at least for me: a model referencing another model, 
> and calling it's detach() method when its own onDetach() is called.
>
> Thanks anyway!
>
> Bas
>
> ----- Original Message ----- 
> From: "Michael Mosmann" <mi...@mosmann.de>
> To: <us...@wicket.apache.org>
> Sent: Wednesday, August 26, 2009 10:13 PM
> Subject: Re: How to detect model "leakage" into session
>
>
>> Am Mittwoch, den 26.08.2009, 21:29 +0200 schrieb Bas Gooren:
>>> Hi all,
>>>
>>> My problem is as follows: I use LoadableDetachableModels throughout my 
>>> application, and have made sure I never use a model without it being 
>>> attached to a component to prevent models which never get their detach() 
>>> method called.
>>> Nonetheless, after hitting two fairly simple pages which list some 
>>> database data in my application, I get a 100kb session which is filled 
>>> with literal strings from model objects.
>>>
>>> I've fired up my (Eclipse) debugger and have stepped through all models 
>>> on one of the pages after setting a breakpoint on the pages onDetach() 
>>> method. I see all LoadableDetachableModels are detached, so I have no 
>>> idea what's causing this.
>>>
>>> What would be a good strategy for finding the source of this problem?
>>
>> IMHO this could be a solution to your problem:
>>
>> http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/
>>
>> CascadingLoadableDetachableModel will detach it's child so that for any
>> used model detach will be called.
>>
>> mm:)
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
> 


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


Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Michael,

This is something which is helpful in case you have models which are not 
"owned" by a component. This is not the case in my application.
Also, the strategy they explain in the blog is something which is quite 
common with wicket, at least for me: a model referencing another model, and 
calling it's detach() method when its own onDetach() is called.

Thanks anyway!

Bas

----- Original Message ----- 
From: "Michael Mosmann" <mi...@mosmann.de>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 26, 2009 10:13 PM
Subject: Re: How to detect model "leakage" into session


> Am Mittwoch, den 26.08.2009, 21:29 +0200 schrieb Bas Gooren:
>> Hi all,
>>
>> My problem is as follows: I use LoadableDetachableModels throughout my 
>> application, and have made sure I never use a model without it being 
>> attached to a component to prevent models which never get their detach() 
>> method called.
>> Nonetheless, after hitting two fairly simple pages which list some 
>> database data in my application, I get a 100kb session which is filled 
>> with literal strings from model objects.
>>
>> I've fired up my (Eclipse) debugger and have stepped through all models 
>> on one of the pages after setting a breakpoint on the pages onDetach() 
>> method. I see all LoadableDetachableModels are detached, so I have no 
>> idea what's causing this.
>>
>> What would be a good strategy for finding the source of this problem?
>
> IMHO this could be a solution to your problem:
>
> http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/
>
> CascadingLoadableDetachableModel will detach it's child so that for any
> used model detach will be called.
>
> mm:)
>
>
> ---------------------------------------------------------------------
> 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: How to detect model "leakage" into session

Posted by Michael Mosmann <mi...@mosmann.de>.
Am Mittwoch, den 26.08.2009, 21:29 +0200 schrieb Bas Gooren:
> Hi all,
> 
> My problem is as follows: I use LoadableDetachableModels throughout my application, and have made sure I never use a model without it being attached to a component to prevent models which never get their detach() method called.
> Nonetheless, after hitting two fairly simple pages which list some database data in my application, I get a 100kb session which is filled with literal strings from model objects.
> 
> I've fired up my (Eclipse) debugger and have stepped through all models on one of the pages after setting a breakpoint on the pages onDetach() method. I see all LoadableDetachableModels are detached, so I have no idea what's causing this.
> 
> What would be a good strategy for finding the source of this problem?

IMHO this could be a solution to your problem:

http://www.wicket-praxis.de/blog/2009/01/03/modell-referenzen/

CascadingLoadableDetachableModel will detach it's child so that for any
used model detach will be called.

mm:)


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


Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Scott,

Well, sometimes the model object is needed to make a rendering decision, so 
I say:

final Foo foo = getModelObject();

if( foo.getX() )
    add( new Label("x", new PropertyModel( getModel(), "x" ) );
else
    add( new Label("x", new PropertyModel( getModel(), "y" ) );

But in this case the final variable foo is garbage collected when it goes 
out of scope, right?

The only object-references in my application are Guice-injected (and thus 
session-safe proxied) daos and services. I have taken particular care to 
never reference model object directly.

But thanks anyway, I'll put it on my list of things to check.

The example you provide is one of the first things I read on the wicket wiki 
when I just started using it: prevent direct access to (large) model objects 
and never share non-static inner model classes between pages.

Bas

----- Original Message ----- 
From: "Scott Swank" <sc...@gmail.com>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 26, 2009 10:11 PM
Subject: Re: How to detect model "leakage" into session


If you are certain that detach is always called then you must have
references to the underlying model objects.  I would look through
every call to IModel#getObject().

One thought is that if you create a final variable and refer to that
variable in an anonymous inner class then you have bound the object to
the component.  E.g.

final Foo foo = fooModel.getObject();
add(new Label("id", whatever){public isVisible(){return foo.isPurple();}});
// now foo is bound to the label, and will end up in the session

Scott

On Wed, Aug 26, 2009 at 12:51 PM, Bas Gooren<ba...@iswd.nl> wrote:
> Sven,
>
> I've been using wicket for over a year, so I'm quite familiar with Model
> usage.
> So thanks for the explanation, but I'm already using 
> CompoundPropertyModels
> and PropertyModels everywhere.
> Because of this it's all the more frustrating to see model contents in my
> session.
>
> Bas
>
> ----- Original Message ----- From: "Sven Meier" <sv...@meiers.net>
> To: <us...@wicket.apache.org>
> Sent: Wednesday, August 26, 2009 9:48 PM
> Subject: Re: How to detect model "leakage" into session
>
>
>> Hi,
>>
>> you're probably doing something like the following:
>>
>> add(new Label("foo", ldm.getObject().getFoo()));
>>
>> Never do that, instead use:
>>
>> add(new Label("foo", new PropertyModel(ldm, "foo")));
>>
>> ... or ...
>>
>> add(new Label("foo", new AbstractReadonlyModel() {
>> public Object getObject() {
>> return ldm.getObject().getFoo());
>> }
>> }));
>>
>> ... or even better ...
>>
>> setModel(new CompoundPropertyModel(ldm));
>>
>> add(new Label("foo")); // -> getFoo()
>> add(new Label("bar")); // -> getBar()
>> add(new Label("baz")); // -> getBaz()
>>
>> HTH
>>
>> Sven
>>
>> On Mi, 2009-08-26 at 21:29 +0200, Bas Gooren wrote:
>>>
>>> Hi all,
>>>
>>> My problem is as follows: I use LoadableDetachableModels throughout my
>>> application, and have made sure I never use a model without it being
>>> attached to a component to prevent models which never get their detach()
>>> method called.
>>> Nonetheless, after hitting two fairly simple pages which list some
>>> database data in my application, I get a 100kb session which is filled 
>>> with
>>> literal strings from model objects.
>>>
>>> I've fired up my (Eclipse) debugger and have stepped through all models
>>> on one of the pages after setting a breakpoint on the pages onDetach()
>>> method. I see all LoadableDetachableModels are detached, so I have no 
>>> idea
>>> what's causing this.
>>>
>>> What would be a good strategy for finding the source of this problem?
>>>
>>> Bas
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

---------------------------------------------------------------------
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: How to detect model "leakage" into session

Posted by Scott Swank <sc...@gmail.com>.
If you are certain that detach is always called then you must have
references to the underlying model objects.  I would look through
every call to IModel#getObject().

One thought is that if you create a final variable and refer to that
variable in an anonymous inner class then you have bound the object to
the component.  E.g.

final Foo foo = fooModel.getObject();
add(new Label("id", whatever){public isVisible(){return foo.isPurple();}});
// now foo is bound to the label, and will end up in the session

Scott

On Wed, Aug 26, 2009 at 12:51 PM, Bas Gooren<ba...@iswd.nl> wrote:
> Sven,
>
> I've been using wicket for over a year, so I'm quite familiar with Model
> usage.
> So thanks for the explanation, but I'm already using CompoundPropertyModels
> and PropertyModels everywhere.
> Because of this it's all the more frustrating to see model contents in my
> session.
>
> Bas
>
> ----- Original Message ----- From: "Sven Meier" <sv...@meiers.net>
> To: <us...@wicket.apache.org>
> Sent: Wednesday, August 26, 2009 9:48 PM
> Subject: Re: How to detect model "leakage" into session
>
>
>> Hi,
>>
>> you're probably doing something like the following:
>>
>>  add(new Label("foo", ldm.getObject().getFoo()));
>>
>> Never do that, instead use:
>>
>>  add(new Label("foo", new PropertyModel(ldm, "foo")));
>>
>> ... or ...
>>
>>  add(new Label("foo", new AbstractReadonlyModel() {
>>   public Object getObject() {
>>     return ldm.getObject().getFoo());
>>   }
>>  }));
>>
>> ... or even better ...
>>
>>  setModel(new CompoundPropertyModel(ldm));
>>
>>  add(new Label("foo")); // -> getFoo()
>>  add(new Label("bar")); // -> getBar()
>>  add(new Label("baz")); // -> getBaz()
>>
>> HTH
>>
>> Sven
>>
>> On Mi, 2009-08-26 at 21:29 +0200, Bas Gooren wrote:
>>>
>>> Hi all,
>>>
>>> My problem is as follows: I use LoadableDetachableModels throughout my
>>> application, and have made sure I never use a model without it being
>>> attached to a component to prevent models which never get their detach()
>>> method called.
>>> Nonetheless, after hitting two fairly simple pages which list some
>>> database data in my application, I get a 100kb session which is filled with
>>> literal strings from model objects.
>>>
>>> I've fired up my (Eclipse) debugger and have stepped through all models
>>> on one of the pages after setting a breakpoint on the pages onDetach()
>>> method. I see all LoadableDetachableModels are detached, so I have no idea
>>> what's causing this.
>>>
>>> What would be a good strategy for finding the source of this problem?
>>>
>>> Bas
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Page redirect after POST

Posted by Jeremy Thomerson <je...@wickettraining.com>.
http://cwiki.apache.org/WICKET/render-strategies.html

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




On Thu, Aug 27, 2009 at 11:01 PM, <bh...@actrix.gen.nz> wrote:
> Hi,
>
> With forms on Wicket pages, it appears that on submit which is HTTP
> POST, Wicket redirects to the same page (the page from where the data
> was sent) ad this is how we show feedback on the form page.
>
> How is it possible to send the rendered form page back to the broser
> as a direct response to the POST, not via a redirect?
>
> Many thanks.
>
> Bernard
>
> ---------------------------------------------------------------------
> 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


Page redirect after POST

Posted by bh...@actrix.gen.nz.
Hi,

With forms on Wicket pages, it appears that on submit which is HTTP
POST, Wicket redirects to the same page (the page from where the data
was sent) ad this is how we show feedback on the form page.

How is it possible to send the rendered form page back to the broser
as a direct response to the POST, not via a redirect?

Many thanks.

Bernard

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


Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Sven,

I've been using wicket for over a year, so I'm quite familiar with Model 
usage.
So thanks for the explanation, but I'm already using CompoundPropertyModels 
and PropertyModels everywhere.
Because of this it's all the more frustrating to see model contents in my 
session.

Bas

----- Original Message ----- 
From: "Sven Meier" <sv...@meiers.net>
To: <us...@wicket.apache.org>
Sent: Wednesday, August 26, 2009 9:48 PM
Subject: Re: How to detect model "leakage" into session


> Hi,
>
> you're probably doing something like the following:
>
>  add(new Label("foo", ldm.getObject().getFoo()));
>
> Never do that, instead use:
>
>  add(new Label("foo", new PropertyModel(ldm, "foo")));
>
> ... or ...
>
>  add(new Label("foo", new AbstractReadonlyModel() {
>    public Object getObject() {
>      return ldm.getObject().getFoo());
>    }
>  }));
>
> ... or even better ...
>
>  setModel(new CompoundPropertyModel(ldm));
>
>  add(new Label("foo")); // -> getFoo()
>  add(new Label("bar")); // -> getBar()
>  add(new Label("baz")); // -> getBaz()
>
> HTH
>
> Sven
>
> On Mi, 2009-08-26 at 21:29 +0200, Bas Gooren wrote:
>> Hi all,
>>
>> My problem is as follows: I use LoadableDetachableModels throughout my 
>> application, and have made sure I never use a model without it being 
>> attached to a component to prevent models which never get their detach() 
>> method called.
>> Nonetheless, after hitting two fairly simple pages which list some 
>> database data in my application, I get a 100kb session which is filled 
>> with literal strings from model objects.
>>
>> I've fired up my (Eclipse) debugger and have stepped through all models 
>> on one of the pages after setting a breakpoint on the pages onDetach() 
>> method. I see all LoadableDetachableModels are detached, so I have no 
>> idea what's causing this.
>>
>> What would be a good strategy for finding the source of this problem?
>>
>> Bas
>
>
> ---------------------------------------------------------------------
> 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: How to detect model "leakage" into session

Posted by Sven Meier <sv...@meiers.net>.
Hi,

you're probably doing something like the following:

  add(new Label("foo", ldm.getObject().getFoo()));

Never do that, instead use:

  add(new Label("foo", new PropertyModel(ldm, "foo")));

... or ...

  add(new Label("foo", new AbstractReadonlyModel() {
    public Object getObject() {
      return ldm.getObject().getFoo());
    }
  }));

... or even better ...

  setModel(new CompoundPropertyModel(ldm));

  add(new Label("foo")); // -> getFoo()
  add(new Label("bar")); // -> getBar()
  add(new Label("baz")); // -> getBaz()

HTH

Sven

On Mi, 2009-08-26 at 21:29 +0200, Bas Gooren wrote:
> Hi all,
> 
> My problem is as follows: I use LoadableDetachableModels throughout my application, and have made sure I never use a model without it being attached to a component to prevent models which never get their detach() method called.
> Nonetheless, after hitting two fairly simple pages which list some database data in my application, I get a 100kb session which is filled with literal strings from model objects.
> 
> I've fired up my (Eclipse) debugger and have stepped through all models on one of the pages after setting a breakpoint on the pages onDetach() method. I see all LoadableDetachableModels are detached, so I have no idea what's causing this.
> 
> What would be a good strategy for finding the source of this problem?
> 
> Bas


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


Re: How to detect model "leakage" into session

Posted by Bas Gooren <ba...@iswd.nl>.
Eelco,

Thanks for your tip.

Bas

----- Original Message ----- 
From: "Eelco Hillenius" <ee...@gmail.com>
To: <us...@wicket.apache.org>
Sent: Thursday, August 27, 2009 10:09 AM
Subject: Re: How to detect model "leakage" into session


> One 'hack' of a way to check whether you have stuff in your session
> that shouldn't be, is to make sure that the objects you don't want
> sticking around are not serializable, and you'll see stacktraces soon
> enough. If that's an options, it's a useful hack...
>
> Eelco
>
> On Wed, Aug 26, 2009 at 12:29 PM, Bas Gooren<ba...@iswd.nl> wrote:
>> Hi all,
>>
>> My problem is as follows: I use LoadableDetachableModels throughout my 
>> application, and have made sure I never use a model without it being 
>> attached to a component to prevent models which never get their detach() 
>> method called.
>> Nonetheless, after hitting two fairly simple pages which list some 
>> database data in my application, I get a 100kb session which is filled 
>> with literal strings from model objects.
>>
>> I've fired up my (Eclipse) debugger and have stepped through all models 
>> on one of the pages after setting a breakpoint on the pages onDetach() 
>> method. I see all LoadableDetachableModels are detached, so I have no 
>> idea what's causing this.
>>
>> What would be a good strategy for finding the source of this problem?
>>
>> Bas
>
> ---------------------------------------------------------------------
> 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: How to detect model "leakage" into session

Posted by Martijn Dashorst <ma...@gmail.com>.
Or check your pages for references to your entities at the end of the request:

	private void testDetachedObjects(final Page page)
	{
		Page responsePage = getResponsePage();
		if (page == null || page.isErrorPage()
			|| (responsePage != null && responsePage.isErrorPage()))
		{
			return;
		}

		try
		{
			NotSerializableException exception = new NotSerializableException();
			EntityAndSerializableChecker checker = new
EntityAndSerializableChecker(exception);
			checker.writeObject(page);
		}
		catch (Exception ex)
		{
			log.error("Couldn't test/serialize the Page: " + page + ", error: " + ex);
		}
	}

Copy the SerializableChecker code (included in Wicket) and modify it
to discover your entities.

Here's a patch (against 1.4) that our app uses to perform the check:

@@ -330,21 +410,40 @@
 		writeObjectMethodCache.clear();
 	}

+	@SuppressWarnings("all")
 	private void check(Object obj)
 	{
-		if (obj == null)
+		if (obj == null || obj.getClass().isAnnotationPresent(Deprecated.class)
+			|| obj.getClass().isAnnotationPresent(SkipClass.class))
 		{
 			return;
 		}

-		Class<?> cls = obj.getClass();
+		Class cls = obj.getClass();
 		nameStack.add(simpleName);
 		traceStack.add(new TraceSlot(obj, fieldDescription));

 		if (!(obj instanceof Serializable) && (!Proxy.isProxyClass(cls)))
 		{
-			throw new WicketNotSerializableException(
-				toPrettyPrintedStack(obj.getClass().getName()), exception);
+			throw new WicketNotSerializableException(toPrettyPrintedStack(obj.getClass().getName())
+				.toString(), exception);
+		}
+		if (obj instanceof IdObject)
+		{
+			Serializable id = ((IdObject) obj).getIdAsSerializable();
+			if (id != null && !(id instanceof Long && ((Long) id) <= 0))
+			{
+				throw new WicketContainsEntityException(toPrettyPrintedStack(
+					obj.getClass().getName()).toString(), exception);
+			}
+			// Deze uitgezet aangezien objecten die nieuw zijn *wel* gewoon in de sessie
+			// mogen komen.
+			// else
+			// {
+			// log.info("New Id Object ("
+			// + obj.getClass().getSimpleName() + ") Found '" + obj
+			// + "' found: " + stack);
+			// }
 		}

 		ObjectStreamClass desc;


On Thu, Aug 27, 2009 at 10:09 AM, Eelco
Hillenius<ee...@gmail.com> wrote:
> One 'hack' of a way to check whether you have stuff in your session
> that shouldn't be, is to make sure that the objects you don't want
> sticking around are not serializable, and you'll see stacktraces soon
> enough. If that's an options, it's a useful hack...
>
> Eelco
>
> On Wed, Aug 26, 2009 at 12:29 PM, Bas Gooren<ba...@iswd.nl> wrote:
>> Hi all,
>>
>> My problem is as follows: I use LoadableDetachableModels throughout my application, and have made sure I never use a model without it being attached to a component to prevent models which never get their detach() method called.
>> Nonetheless, after hitting two fairly simple pages which list some database data in my application, I get a 100kb session which is filled with literal strings from model objects.
>>
>> I've fired up my (Eclipse) debugger and have stepped through all models on one of the pages after setting a breakpoint on the pages onDetach() method. I see all LoadableDetachableModels are detached, so I have no idea what's causing this.
>>
>> What would be a good strategy for finding the source of this problem?
>>
>> Bas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0

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


Re: How to detect model "leakage" into session

Posted by Eelco Hillenius <ee...@gmail.com>.
One 'hack' of a way to check whether you have stuff in your session
that shouldn't be, is to make sure that the objects you don't want
sticking around are not serializable, and you'll see stacktraces soon
enough. If that's an options, it's a useful hack...

Eelco

On Wed, Aug 26, 2009 at 12:29 PM, Bas Gooren<ba...@iswd.nl> wrote:
> Hi all,
>
> My problem is as follows: I use LoadableDetachableModels throughout my application, and have made sure I never use a model without it being attached to a component to prevent models which never get their detach() method called.
> Nonetheless, after hitting two fairly simple pages which list some database data in my application, I get a 100kb session which is filled with literal strings from model objects.
>
> I've fired up my (Eclipse) debugger and have stepped through all models on one of the pages after setting a breakpoint on the pages onDetach() method. I see all LoadableDetachableModels are detached, so I have no idea what's causing this.
>
> What would be a good strategy for finding the source of this problem?
>
> Bas

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