You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2008/05/02 16:46:22 UTC

What is session.dirty() for?

Hi!

I have been coding without invoking session.dirty. Browsing framework
code, I can see it is used. What does it accomplish and where should I
have used it in my own code?

**
Martin

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


Re: What is session.dirty() for?

Posted by Matej Knopp <ma...@gmail.com>.
On Sun, May 4, 2008 at 8:09 AM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> > If you subclassed the Session class and your attributes are properties
>  > of the subclass.
>
>  Yes I did.
>
>
>  > But you are required to call session.dirty() only if your pages are
>  > stateless and your application is deployed on cluster.
>
>  Why the session.dirty is called by the framework after modifying
>  feedback messages. I would expect feedback messages to be associated
>  only with stateful pages. So .dirty should be called in stateful
>  situations too?
No. Your assumption of feedback messages present only with stateful
pages is wrong. A stateless page can register feedback message, even a
flash message (feedback message not associated with a page).
>
>  Darn. This is not fell like a very clean design, does it? Practically,
>  the session is dirty after every request. I cannot imagine otherwise.
>  Does this mean that session is NOT the place to store state?
I have no idea how did you come to that conclusion. Session is the
place to store state shared between pages (except for simple object
passing from page to page, you can use page constructor for it).
>
>  The problem with storing the state in a page is that when the page is
>  re-instantiated on a reload the instance variables are reset. Storing
>  the variables into the session overcomes this problem, but if I always
>  have to call .dirty my code gets cluttered and brittle - how can I
>  test that my app is now cluster-safe?
Are you page stateless? If not, you don't have to worry about it. Also
if you don't want new page instance created on reload yet you want the
url to be bookmarkable, mount the page using HybridUrlCodingStrategy.
>
>  Ofcourse I could wrap all my state variables in a proxy object which
>  handles the dirty automatically, but this seems like an overkill.
>
>  I hope this was just a misunderstanding :)
>

-Matej

>  **
>  Martin
>
>  2008/5/3 Johan Compagner <jc...@gmail.com>:
>
>
> > Nop thats the best thing todo
>  >
>  >
>  >
>  >  On 5/3/08, Michael Allan <mi...@zelea.com> wrote:
>  >  > Matej Knopp wrote:
>  >  > > Martin Makundi wrote:
>  >  > > >
>  >  > > >  Let's say I have some variables in my session. If these variables
>  >  > > >  change, do I have to call session.dirty?
>  >  > >
>  >  > > If you subclassed the Session class and your attributes are properties
>  >  > > of the subclass.
>  >  > >
>  >  > > But you are required to call session.dirty() only if your pages are
>  >  > > stateless and your application is deployed on cluster.
>  >  >
>  >  > Just to cover all eventualities, Matej (in case we later move to a
>  >  > cluster) is there any harm in *always* calling session.dirty(), when a
>  >  > Session field changes value?
>  >  >
>  >  > --
>  >  > Michael Allan
>  >  >
>  >  > Toronto, 647-436-4521
>  >  > http://zelea.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
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Resizable and reorderable grid components.
http://www.inmethod.com

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


Re: What is session.dirty() for?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> If you subclassed the Session class and your attributes are properties
> of the subclass.

Yes I did.

> But you are required to call session.dirty() only if your pages are
> stateless and your application is deployed on cluster.

Why the session.dirty is called by the framework after modifying
feedback messages. I would expect feedback messages to be associated
only with stateful pages. So .dirty should be called in stateful
situations too?

Darn. This is not fell like a very clean design, does it? Practically,
the session is dirty after every request. I cannot imagine otherwise.
Does this mean that session is NOT the place to store state?

The problem with storing the state in a page is that when the page is
re-instantiated on a reload the instance variables are reset. Storing
the variables into the session overcomes this problem, but if I always
have to call .dirty my code gets cluttered and brittle - how can I
test that my app is now cluster-safe?

Ofcourse I could wrap all my state variables in a proxy object which
handles the dirty automatically, but this seems like an overkill.

I hope this was just a misunderstanding :)

**
Martin

2008/5/3 Johan Compagner <jc...@gmail.com>:
> Nop thats the best thing todo
>
>
>
>  On 5/3/08, Michael Allan <mi...@zelea.com> wrote:
>  > Matej Knopp wrote:
>  > > Martin Makundi wrote:
>  > > >
>  > > >  Let's say I have some variables in my session. If these variables
>  > > >  change, do I have to call session.dirty?
>  > >
>  > > If you subclassed the Session class and your attributes are properties
>  > > of the subclass.
>  > >
>  > > But you are required to call session.dirty() only if your pages are
>  > > stateless and your application is deployed on cluster.
>  >
>  > Just to cover all eventualities, Matej (in case we later move to a
>  > cluster) is there any harm in *always* calling session.dirty(), when a
>  > Session field changes value?
>  >
>  > --
>  > Michael Allan
>  >
>  > Toronto, 647-436-4521
>  > http://zelea.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
>
>

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


Re: What is session.dirty() for?

Posted by Johan Compagner <jc...@gmail.com>.
Nop thats the best thing todo

On 5/3/08, Michael Allan <mi...@zelea.com> wrote:
> Matej Knopp wrote:
> > Martin Makundi wrote:
> > >
> > >  Let's say I have some variables in my session. If these variables
> > >  change, do I have to call session.dirty?
> >
> > If you subclassed the Session class and your attributes are properties
> > of the subclass.
> >
> > But you are required to call session.dirty() only if your pages are
> > stateless and your application is deployed on cluster.
>
> Just to cover all eventualities, Matej (in case we later move to a
> cluster) is there any harm in *always* calling session.dirty(), when a
> Session field changes value?
>
> --
> Michael Allan
>
> Toronto, 647-436-4521
> http://zelea.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: What is session.dirty() for?

Posted by Michael Allan <mi...@zelea.com>.
Matej Knopp wrote:
> Martin Makundi wrote:
> >
> >  Let's say I have some variables in my session. If these variables
> >  change, do I have to call session.dirty?
> 
> If you subclassed the Session class and your attributes are properties
> of the subclass.
> 
> But you are required to call session.dirty() only if your pages are
> stateless and your application is deployed on cluster.

Just to cover all eventualities, Matej (in case we later move to a
cluster) is there any harm in *always* calling session.dirty(), when a
Session field changes value?

-- 
Michael Allan

Toronto, 647-436-4521
http://zelea.com/


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


Re: What is session.dirty() for?

Posted by Matej Knopp <ma...@gmail.com>.
On Fri, May 2, 2008 at 5:12 PM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> Could you please elaborate what you mean by "session object has changed"?
>
>  Let's say I have some variables in my session. If these variables
>  change, do I have to call session.dirty?

If you subclassed the Session class and your attributes are properties
of the subclass.

But you are required to call session.dirty() only if your pages are
stateless and your application is deployed on cluster.

-Matej

>
>  **
>  Martin
>
>  2008/5/2 Matej Knopp <ma...@gmail.com>:
>
>
> > Hi,
>  >
>  >  session.dirty() should be invoked when the session object has changed,
>  >  so that wicket changes the http session attribute to make cluster
>  >  replicate the session object (assuming you're running in clustered
>  >  environment).
>  >
>  >  I think the only case when you need to call dirty() yourself is when
>  >  your application has only stateless pages and you have a statefull
>  >  session object that you need to replicate accros cluster. But IMHO
>  >  that's not very common usecase.
>  >
>  >  -Matej
>  >
>  >
>  >
>  >  On Fri, May 2, 2008 at 4:46 PM, Martin Makundi
>  >  <ma...@koodaripalvelut.com> wrote:
>  >  > Hi!
>  >  >
>  >  >  I have been coding without invoking session.dirty. Browsing framework
>  >  >  code, I can see it is used. What does it accomplish and where should I
>  >  >  have used it in my own code?
>  >  >
>  >  >  **
>  >  >  Martin
>  >  >
>  >  >  ---------------------------------------------------------------------
>  >  >  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  >  >  For additional commands, e-mail: users-help@wicket.apache.org
>  >  >
>  >  >
>  >
>  >
>  >
>  >  --
>  >  Resizable and reorderable grid components.
>  >  http://www.inmethod.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
>
>



-- 
Resizable and reorderable grid components.
http://www.inmethod.com

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


Re: What is session.dirty() for?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Could you please elaborate what you mean by "session object has changed"?

Let's say I have some variables in my session. If these variables
change, do I have to call session.dirty?

**
Martin

2008/5/2 Matej Knopp <ma...@gmail.com>:
> Hi,
>
>  session.dirty() should be invoked when the session object has changed,
>  so that wicket changes the http session attribute to make cluster
>  replicate the session object (assuming you're running in clustered
>  environment).
>
>  I think the only case when you need to call dirty() yourself is when
>  your application has only stateless pages and you have a statefull
>  session object that you need to replicate accros cluster. But IMHO
>  that's not very common usecase.
>
>  -Matej
>
>
>
>  On Fri, May 2, 2008 at 4:46 PM, Martin Makundi
>  <ma...@koodaripalvelut.com> wrote:
>  > Hi!
>  >
>  >  I have been coding without invoking session.dirty. Browsing framework
>  >  code, I can see it is used. What does it accomplish and where should I
>  >  have used it in my own code?
>  >
>  >  **
>  >  Martin
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  >  For additional commands, e-mail: users-help@wicket.apache.org
>  >
>  >
>
>
>
>  --
>  Resizable and reorderable grid components.
>  http://www.inmethod.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: What is session.dirty() for?

Posted by Matej Knopp <ma...@gmail.com>.
Hi,

session.dirty() should be invoked when the session object has changed,
so that wicket changes the http session attribute to make cluster
replicate the session object (assuming you're running in clustered
environment).

I think the only case when you need to call dirty() yourself is when
your application has only stateless pages and you have a statefull
session object that you need to replicate accros cluster. But IMHO
that's not very common usecase.

-Matej

On Fri, May 2, 2008 at 4:46 PM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> Hi!
>
>  I have been coding without invoking session.dirty. Browsing framework
>  code, I can see it is used. What does it accomplish and where should I
>  have used it in my own code?
>
>  **
>  Martin
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Resizable and reorderable grid components.
http://www.inmethod.com

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