You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by smallufo <sm...@gmail.com> on 2008/06/04 20:57:33 UTC

Does wicket favor composite session obj?

According to wicket API docs , I have a question.
Does wicket favor composite session object ?
That is , if my site has some independent apps , each has its custom setting
object.
It seems I have to associate these objects to one root session object :

like this :

App1Setting setting1 = ((RootSession)getSession()).getApp1Setting();
App2Setting setting2 = ((RootSession)getSession()).getApp2Setting();


Is it correct ?

Re: Does wicket favor composite session obj?

Posted by smallufo <sm...@gmail.com>.
Well , I am not sure how to debug into the session .
I printed out the session.getId() and session.sequence , after login success
, and back to the loginPage
Both are the identical ...

MySession s = (MySession) getSession();
s.getLoginData().setUser(u);
System.out.println("After login success , id = " + s.getId() + " , seq = " +
s.sequence);
s.dirty();

In LoginPage :
MySession ds = (MySession) getSession();
System.out.println("In login panel , id = " + ds.getId() + " , seq = " +
ds.sequence);
User u = s.getLoginData().getUser(); // still null

After login success , id = abcPhnwUGJlEO5BVFmuPr , seq = 25
In login panel , id = abcPhnwUGJlEO5BVFmuPr , seq = 25

I think the both sessions are the same...


2008/6/5 Maurice Marrink <ma...@gmail.com>:

> Hmm it is getting late and i may be missing something, but that should
> work.
> Can you check if you have a temporary session? that is the only
> logical explanation i can come up with at this time :)
> if it is it is replaced by a new session on each request, call bind()
> to fix that.
> if not you might want to debug session#requestDetached and check what
> happens there and if the session is still the same in the next
> request.
>
> Maurice
>
> On Wed, Jun 4, 2008 at 11:47 PM, smallufo <sm...@gmail.com> wrote:
> > Oops , thanks for your hint....
> >
> > But it seems not working ......
> >
> > User loginedUser = userDao.getUserFromLoginName(loginName);
> > if (loginedUser != null)
> > {
> >  MySession mySession = (MySession) getSession();
> >  mySession .getLoginData().setUser(loginedUser);
> >  mySession .dirty(); //add this line
> >  setResponsePage(LoginPage.class);
> > }
> >
> > In LoginPage :
> > User user = MySession.get().getLoginData().getUser();
> > Here , user is still null. Why ?
> >
> >
> >
> > 2008/6/5 Maurice Marrink <ma...@gmail.com>:
> >
> >> Mark the session as dirty. Wicket cannot detect if some property of a
> >> pojo has been updated in your session.
> >> By marking the session as dirty wicket will (re)save everything.
> >>
> >> Maurice
> >>
> >> On Wed, Jun 4, 2008 at 10:52 PM, smallufo <sm...@gmail.com> wrote:
> >> > Thank you .
> >> > It solves my confusion.
> >> > But I have another question.
> >> > It seems wicket can only handle "one-reference" composite session.
> >> > That is , a root session object , and a associated session object.
> >> > If the associating session object has another associating object , it
> >> will
> >> > not be saved/updated.
> >> >
> >> > for example :
> >> > MySession.get().getLocation().setCityName("Taipei")
> >> > it will automatically save the value.
> >> >
> >> > But if the Location has another associated object :
> >> > MySession.get().getLocation().getCity().setName("Taipei");
> >> > After reloading , the city's name is not updated.
> >> > It seems wicket cannot save the reference.
> >> >
> >> > I know maybe MySession.get().getLocation().setCity(new City(...)) can
> >> solve
> >> > this problem
> >> > But is this the only way ?
> >> >
> >> >
> >> >
> >> >
> >> > 2008/6/5 Eelco Hillenius <ee...@gmail.com>:
> >> >
> >> >> > My question is , if I don't want to use HttpSession (string
> property
> >> is
> >> >> > error-prone)
> >> >> > I prefer the wicket way.
> >> >> > I found if I go the wicket way , it results in the "composite
> session
> >> >> > object" , it is correct ?
> >> >> >
> >> >> > PageAsetting settingA =
> ((MySession)getSession()).getPageAsetting();
> >> >> > PageBsetting settingB =
> ((MySession)getSession()).getPageBsetting();
> >> >>
> >> >> Yeah, that looks good.
> >> >>
> >> >> Btw, in your session class you can do:
> >> >>
> >> >> public static MySession get() { return (MySession)Session.get(); }
> >> >>
> >> >> so that you can do:
> >> >>
> >> >> PageAsetting settingA = MySession.get().getPageAsetting();
> >> >>
> >> >> which is a bit nicer imho.
> >> >>
> >> >> > If I have more pages , more settings , I have to "hook" these
> setting
> >> >> > objects to the root session object .
> >> >> > Is it what wicket's favorable way ?
> >> >>
> >> >> Yeah, if you're sure these settings should be retained for the
> >> >> duration of the whole session, that's what you can do.
> >> >>
> >> >> Eelco
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> 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: Does wicket favor composite session obj?

Posted by Maurice Marrink <ma...@gmail.com>.
Hmm it is getting late and i may be missing something, but that should work.
Can you check if you have a temporary session? that is the only
logical explanation i can come up with at this time :)
if it is it is replaced by a new session on each request, call bind()
to fix that.
if not you might want to debug session#requestDetached and check what
happens there and if the session is still the same in the next
request.

Maurice

On Wed, Jun 4, 2008 at 11:47 PM, smallufo <sm...@gmail.com> wrote:
> Oops , thanks for your hint....
>
> But it seems not working ......
>
> User loginedUser = userDao.getUserFromLoginName(loginName);
> if (loginedUser != null)
> {
>  MySession mySession = (MySession) getSession();
>  mySession .getLoginData().setUser(loginedUser);
>  mySession .dirty(); //add this line
>  setResponsePage(LoginPage.class);
> }
>
> In LoginPage :
> User user = MySession.get().getLoginData().getUser();
> Here , user is still null. Why ?
>
>
>
> 2008/6/5 Maurice Marrink <ma...@gmail.com>:
>
>> Mark the session as dirty. Wicket cannot detect if some property of a
>> pojo has been updated in your session.
>> By marking the session as dirty wicket will (re)save everything.
>>
>> Maurice
>>
>> On Wed, Jun 4, 2008 at 10:52 PM, smallufo <sm...@gmail.com> wrote:
>> > Thank you .
>> > It solves my confusion.
>> > But I have another question.
>> > It seems wicket can only handle "one-reference" composite session.
>> > That is , a root session object , and a associated session object.
>> > If the associating session object has another associating object , it
>> will
>> > not be saved/updated.
>> >
>> > for example :
>> > MySession.get().getLocation().setCityName("Taipei")
>> > it will automatically save the value.
>> >
>> > But if the Location has another associated object :
>> > MySession.get().getLocation().getCity().setName("Taipei");
>> > After reloading , the city's name is not updated.
>> > It seems wicket cannot save the reference.
>> >
>> > I know maybe MySession.get().getLocation().setCity(new City(...)) can
>> solve
>> > this problem
>> > But is this the only way ?
>> >
>> >
>> >
>> >
>> > 2008/6/5 Eelco Hillenius <ee...@gmail.com>:
>> >
>> >> > My question is , if I don't want to use HttpSession (string property
>> is
>> >> > error-prone)
>> >> > I prefer the wicket way.
>> >> > I found if I go the wicket way , it results in the "composite session
>> >> > object" , it is correct ?
>> >> >
>> >> > PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
>> >> > PageBsetting settingB = ((MySession)getSession()).getPageBsetting();
>> >>
>> >> Yeah, that looks good.
>> >>
>> >> Btw, in your session class you can do:
>> >>
>> >> public static MySession get() { return (MySession)Session.get(); }
>> >>
>> >> so that you can do:
>> >>
>> >> PageAsetting settingA = MySession.get().getPageAsetting();
>> >>
>> >> which is a bit nicer imho.
>> >>
>> >> > If I have more pages , more settings , I have to "hook" these setting
>> >> > objects to the root session object .
>> >> > Is it what wicket's favorable way ?
>> >>
>> >> Yeah, if you're sure these settings should be retained for the
>> >> duration of the whole session, that's what you can do.
>> >>
>> >> Eelco
>> >>
>> >> ---------------------------------------------------------------------
>> >> 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: Does wicket favor composite session obj?

Posted by Johan Compagner <jc...@gmail.com>.
are you sure you store it correctly?
for example is the LoginData object the same? (if you do a system out of
that or check it in the debugger)
Because if it is then the user field that it should have cant be just
suddenly null

johan


On Wed, Jun 4, 2008 at 11:47 PM, smallufo <sm...@gmail.com> wrote:

> Oops , thanks for your hint....
>
> But it seems not working ......
>
> User loginedUser = userDao.getUserFromLoginName(loginName);
> if (loginedUser != null)
> {
>  MySession mySession = (MySession) getSession();
>  mySession .getLoginData().setUser(loginedUser);
>  mySession .dirty(); //add this line
>  setResponsePage(LoginPage.class);
> }
>
> In LoginPage :
> User user = MySession.get().getLoginData().getUser();
> Here , user is still null. Why ?
>
>
>
> 2008/6/5 Maurice Marrink <ma...@gmail.com>:
>
> > Mark the session as dirty. Wicket cannot detect if some property of a
> > pojo has been updated in your session.
> > By marking the session as dirty wicket will (re)save everything.
> >
> > Maurice
> >
> > On Wed, Jun 4, 2008 at 10:52 PM, smallufo <sm...@gmail.com> wrote:
> > > Thank you .
> > > It solves my confusion.
> > > But I have another question.
> > > It seems wicket can only handle "one-reference" composite session.
> > > That is , a root session object , and a associated session object.
> > > If the associating session object has another associating object , it
> > will
> > > not be saved/updated.
> > >
> > > for example :
> > > MySession.get().getLocation().setCityName("Taipei")
> > > it will automatically save the value.
> > >
> > > But if the Location has another associated object :
> > > MySession.get().getLocation().getCity().setName("Taipei");
> > > After reloading , the city's name is not updated.
> > > It seems wicket cannot save the reference.
> > >
> > > I know maybe MySession.get().getLocation().setCity(new City(...)) can
> > solve
> > > this problem
> > > But is this the only way ?
> > >
> > >
> > >
> > >
> > > 2008/6/5 Eelco Hillenius <ee...@gmail.com>:
> > >
> > >> > My question is , if I don't want to use HttpSession (string property
> > is
> > >> > error-prone)
> > >> > I prefer the wicket way.
> > >> > I found if I go the wicket way , it results in the "composite
> session
> > >> > object" , it is correct ?
> > >> >
> > >> > PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
> > >> > PageBsetting settingB = ((MySession)getSession()).getPageBsetting();
> > >>
> > >> Yeah, that looks good.
> > >>
> > >> Btw, in your session class you can do:
> > >>
> > >> public static MySession get() { return (MySession)Session.get(); }
> > >>
> > >> so that you can do:
> > >>
> > >> PageAsetting settingA = MySession.get().getPageAsetting();
> > >>
> > >> which is a bit nicer imho.
> > >>
> > >> > If I have more pages , more settings , I have to "hook" these
> setting
> > >> > objects to the root session object .
> > >> > Is it what wicket's favorable way ?
> > >>
> > >> Yeah, if you're sure these settings should be retained for the
> > >> duration of the whole session, that's what you can do.
> > >>
> > >> Eelco
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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: Does wicket favor composite session obj?

Posted by smallufo <sm...@gmail.com>.
Oops , thanks for your hint....

But it seems not working ......

User loginedUser = userDao.getUserFromLoginName(loginName);
if (loginedUser != null)
{
  MySession mySession = (MySession) getSession();
  mySession .getLoginData().setUser(loginedUser);
  mySession .dirty(); //add this line
  setResponsePage(LoginPage.class);
}

In LoginPage :
User user = MySession.get().getLoginData().getUser();
Here , user is still null. Why ?



2008/6/5 Maurice Marrink <ma...@gmail.com>:

> Mark the session as dirty. Wicket cannot detect if some property of a
> pojo has been updated in your session.
> By marking the session as dirty wicket will (re)save everything.
>
> Maurice
>
> On Wed, Jun 4, 2008 at 10:52 PM, smallufo <sm...@gmail.com> wrote:
> > Thank you .
> > It solves my confusion.
> > But I have another question.
> > It seems wicket can only handle "one-reference" composite session.
> > That is , a root session object , and a associated session object.
> > If the associating session object has another associating object , it
> will
> > not be saved/updated.
> >
> > for example :
> > MySession.get().getLocation().setCityName("Taipei")
> > it will automatically save the value.
> >
> > But if the Location has another associated object :
> > MySession.get().getLocation().getCity().setName("Taipei");
> > After reloading , the city's name is not updated.
> > It seems wicket cannot save the reference.
> >
> > I know maybe MySession.get().getLocation().setCity(new City(...)) can
> solve
> > this problem
> > But is this the only way ?
> >
> >
> >
> >
> > 2008/6/5 Eelco Hillenius <ee...@gmail.com>:
> >
> >> > My question is , if I don't want to use HttpSession (string property
> is
> >> > error-prone)
> >> > I prefer the wicket way.
> >> > I found if I go the wicket way , it results in the "composite session
> >> > object" , it is correct ?
> >> >
> >> > PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
> >> > PageBsetting settingB = ((MySession)getSession()).getPageBsetting();
> >>
> >> Yeah, that looks good.
> >>
> >> Btw, in your session class you can do:
> >>
> >> public static MySession get() { return (MySession)Session.get(); }
> >>
> >> so that you can do:
> >>
> >> PageAsetting settingA = MySession.get().getPageAsetting();
> >>
> >> which is a bit nicer imho.
> >>
> >> > If I have more pages , more settings , I have to "hook" these setting
> >> > objects to the root session object .
> >> > Is it what wicket's favorable way ?
> >>
> >> Yeah, if you're sure these settings should be retained for the
> >> duration of the whole session, that's what you can do.
> >>
> >> Eelco
> >>
> >> ---------------------------------------------------------------------
> >> 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: Does wicket favor composite session obj?

Posted by Maurice Marrink <ma...@gmail.com>.
Mark the session as dirty. Wicket cannot detect if some property of a
pojo has been updated in your session.
By marking the session as dirty wicket will (re)save everything.

Maurice

On Wed, Jun 4, 2008 at 10:52 PM, smallufo <sm...@gmail.com> wrote:
> Thank you .
> It solves my confusion.
> But I have another question.
> It seems wicket can only handle "one-reference" composite session.
> That is , a root session object , and a associated session object.
> If the associating session object has another associating object , it will
> not be saved/updated.
>
> for example :
> MySession.get().getLocation().setCityName("Taipei")
> it will automatically save the value.
>
> But if the Location has another associated object :
> MySession.get().getLocation().getCity().setName("Taipei");
> After reloading , the city's name is not updated.
> It seems wicket cannot save the reference.
>
> I know maybe MySession.get().getLocation().setCity(new City(...)) can solve
> this problem
> But is this the only way ?
>
>
>
>
> 2008/6/5 Eelco Hillenius <ee...@gmail.com>:
>
>> > My question is , if I don't want to use HttpSession (string property is
>> > error-prone)
>> > I prefer the wicket way.
>> > I found if I go the wicket way , it results in the "composite session
>> > object" , it is correct ?
>> >
>> > PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
>> > PageBsetting settingB = ((MySession)getSession()).getPageBsetting();
>>
>> Yeah, that looks good.
>>
>> Btw, in your session class you can do:
>>
>> public static MySession get() { return (MySession)Session.get(); }
>>
>> so that you can do:
>>
>> PageAsetting settingA = MySession.get().getPageAsetting();
>>
>> which is a bit nicer imho.
>>
>> > If I have more pages , more settings , I have to "hook" these setting
>> > objects to the root session object .
>> > Is it what wicket's favorable way ?
>>
>> Yeah, if you're sure these settings should be retained for the
>> duration of the whole session, that's what you can do.
>>
>> Eelco
>>
>> ---------------------------------------------------------------------
>> 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: Does wicket favor composite session obj?

Posted by smallufo <sm...@gmail.com>.
Thank you .
It solves my confusion.
But I have another question.
It seems wicket can only handle "one-reference" composite session.
That is , a root session object , and a associated session object.
If the associating session object has another associating object , it will
not be saved/updated.

for example :
MySession.get().getLocation().setCityName("Taipei")
it will automatically save the value.

But if the Location has another associated object :
MySession.get().getLocation().getCity().setName("Taipei");
After reloading , the city's name is not updated.
It seems wicket cannot save the reference.

I know maybe MySession.get().getLocation().setCity(new City(...)) can solve
this problem
But is this the only way ?




2008/6/5 Eelco Hillenius <ee...@gmail.com>:

> > My question is , if I don't want to use HttpSession (string property is
> > error-prone)
> > I prefer the wicket way.
> > I found if I go the wicket way , it results in the "composite session
> > object" , it is correct ?
> >
> > PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
> > PageBsetting settingB = ((MySession)getSession()).getPageBsetting();
>
> Yeah, that looks good.
>
> Btw, in your session class you can do:
>
> public static MySession get() { return (MySession)Session.get(); }
>
> so that you can do:
>
> PageAsetting settingA = MySession.get().getPageAsetting();
>
> which is a bit nicer imho.
>
> > If I have more pages , more settings , I have to "hook" these setting
> > objects to the root session object .
> > Is it what wicket's favorable way ?
>
> Yeah, if you're sure these settings should be retained for the
> duration of the whole session, that's what you can do.
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Does wicket favor composite session obj?

Posted by Eelco Hillenius <ee...@gmail.com>.
> My question is , if I don't want to use HttpSession (string property is
> error-prone)
> I prefer the wicket way.
> I found if I go the wicket way , it results in the "composite session
> object" , it is correct ?
>
> PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
> PageBsetting settingB = ((MySession)getSession()).getPageBsetting();

Yeah, that looks good.

Btw, in your session class you can do:

public static MySession get() { return (MySession)Session.get(); }

so that you can do:

PageAsetting settingA = MySession.get().getPageAsetting();

which is a bit nicer imho.

> If I have more pages , more settings , I have to "hook" these setting
> objects to the root session object .
> Is it what wicket's favorable way ?

Yeah, if you're sure these settings should be retained for the
duration of the whole session, that's what you can do.

Eelco

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


Re: Does wicket favor composite session obj?

Posted by smallufo <sm...@gmail.com>.
Thanks for replying so quickly.
I think you misunderstood. Maybe because my previous post "independent apps"
make you confuse. I apology first.
My "independent apps" are , in fact , different pages.
They are under the same WEB-APP , maybe share the same user-base.
They just process different calculation , saving user's preference in
session (not to DB).
For example ,
In PageA , panelA1 is minimized , panel A2 is maximized ,
In PageB , panelB1 is maximized , panelB2 is minimized ...etc.

My question is , if I don't want to use HttpSession (string property is
error-prone)
I prefer the wicket way.
I found if I go the wicket way , it results in the "composite session
object" , it is correct ?

PageAsetting settingA = ((MySession)getSession()).getPageAsetting();
PageBsetting settingB = ((MySession)getSession()).getPageBsetting();

Just like the above codes...
I have to associate each page's setting object to a root session object
(MySession).
Yes , it works fine...

but ...

If I have more pages , more settings , I have to "hook" these setting
objects to the root session object .
Is it what wicket's favorable way ?

Re: Does wicket favor composite session obj?

Posted by Eelco Hillenius <ee...@gmail.com>.
By default, Wicket will create separate session objects for each
application. If you want to share info between multiple Wicket
sessions, you'll have to access the underlying HttpSession object.
Should be relatively easy to create an abstraction for that yourself.

Eelco

On Wed, Jun 4, 2008 at 11:57 AM, smallufo <sm...@gmail.com> wrote:
> According to wicket API docs , I have a question.
> Does wicket favor composite session object ?
> That is , if my site has some independent apps , each has its custom setting
> object.
> It seems I have to associate these objects to one root session object :
>
> like this :
>
> App1Setting setting1 = ((RootSession)getSession()).getApp1Setting();
> App2Setting setting2 = ((RootSession)getSession()).getApp2Setting();
>
>
> Is it correct ?
>

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