On Fri, Nov 13, 2009 at 5:21 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:

>
> Hi,
>
> I seem to have a problem with SessionVars which I try to initialize in
> a LocRewrite.
>
> This is an entry point url to the app. It receives some parameters from
> the url, picks out the parameters and puts them in SessionVars and
> rewrites the request.
>
> I have problems setting the SessionVar when I hit the url in a clean
> browser (ie with no session)
>
> This is the code:
>  private object curAccountId extends SessionVar[Box[Long]](Empty)
>
>  private object curAccount extends RequestVar[Box[Account]] ({
>    println("read:"+curAccountId);
>    val found = currentAccountId.flatMap(id => getSingleton.find(id));
>    println("Found: "+found);
>    found})  with CleanRequestVarOnSessionTransition
>
>  def currentAccountId: Box[Long] = curAccountId.is
>  def currentAccount: Box[Account] = curAccount.is
>  def currentAccount_=(account: Box[Account]) {
>    println("set account: "+account);
>    curAccount.remove
>    curAccountId.remove
>    curAccountId.set({val s = account.map{a => a.id.is}; println("set:
> "+s);s});
>    curAccount.set(account);
>    println("read2:"+curAccountId.is)
>  }
>
> In the LocRewrite I call Account.setCurrentAccount = someAccount
>
> When the URL is hit in a clean browser, this is logged:
>
> set account: Full(dk.fleetzone.model.Account={name=Demo Account,id=1})
> set: Full(1)
> read2:Empty
>
> If I hit the login page first (and nothing else, but I believe it triggers
> the
> creation of a http session), and the exact same url, this is logged:
>
> set account: Full(dk.fleetzone.model.Account={name=Demo Account,id=1})
> set: Full(1)
> read2:Full(1)
>
> Any clues??
>

Yes.  The rewrite phase takes place very early in the HTTP request/response
cycle.  It takes place before the statelessDispatch call.  The
statelessDispatch call is very important for REST style APIs as it does
*not* cause the creation of a session, thus for lots of API calls, we don't
have a session created for each call.

The rewrite phase has to come before the statelessDispatch phase because the
request has to be properly rewritten before being pattern matched against
the partial functions that define the statelessDispatch

Based on some of your prior needs, I've made the session available during
the rewrite phase, but it's only if the session actually exists (basically,
the request is checked for a session, but the request is not told "create
one if it doesn't already exists".

So, the first request from a browser does not have a session and thus does
not have session vars.  Is there a way you can use RequestVars here?


>
> /Jeppe
>
>
>
>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to