Re: [Lift] Resuming a Statefull Snippet.

2010-03-04 Thread David Pollak
On Thu, Mar 4, 2010 at 2:00 PM, andythedestroyer  wrote:

> Hello,
>
> I have a simple use case where there is a 2 page form wizard then a
> redirect to a third party ( for some external validation ) which
> redirects back to a third and final page of the wizard.
>
> I know I could just use snippets and SessionVars to manage this but I
> have been using StatefullSnippets and would like to try to solve this
> problem rather than accept failure and use another method.
>
> I pass the url for the third page to the third party to redirect to
> when their work is done. The problem is the snippet state is lost
> after the redirect. I have tried many different things and it seems
> like something like this should work.
>
> // in the processing done before redirect to third party.
> // assemble the return path url.
>
> class Wizard extends StatefulSnippet with Logger {
> 
> def doRedirect = {
> val returnPath = urlEncode(S.hostAndPath + ( link("/lastPage", () =>
> redirectTo("/lastPage"), NodeSeq.Empty) \ "@href).text)
>
> redirectTo( third_party_url +"?return=" + returnPath)
> }
> }
>
>
Try:

def doRedirect {
  val tmp = Helpers.randomString(20)

  S.addHighLevelSessionDispatcher("wizard", {
 case Req(List(tmp), _, _) => () => {
 S.removeHighLevelSessionDispatcher("wizard")
 redirectTo("/lastPage")
   }
   }

   val returnPath= urlEncode(S.hostAndPath + tmp)

   S.redirectTo(third_party_url+"?return=" + returnPath)
}


The high level session dispatcher was built for this very reason... further,
the return URL is random and only associated with the current session so it
makes hijacking any information or redirecting other sessions back to the
URL a non-issue.

Thanks,

David


> This does generate a return path like "http://localhost:8080/lastPage?
> F1151306194165AHF=_" , however all state is gone after the third party
> redirects back to the site, however if I don't redirect to the third
> party and instead redirect the "val returnPath" I construct directly,
> state is maintained.
>
> Is it possible to resume my StatefulSnippet? Or shall I just use
> something else?
>
> Thanks to all who read and or respond.
>
> -Andy
>
> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lift...@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.
>
>


-- 
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 lift...@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.



Re: [Lift] Resuming a Statefull Snippet.

2010-03-04 Thread Naftoli Gugenheim
You have to save the snippet instance in a variable somewhere that won't go out 
of scope, and then in redirectTo's second parameter write 
instance.registerThisSnippet.

-
andythedestroyer wrote:

Hello,

I have a simple use case where there is a 2 page form wizard then a
redirect to a third party ( for some external validation ) which
redirects back to a third and final page of the wizard.

I know I could just use snippets and SessionVars to manage this but I
have been using StatefullSnippets and would like to try to solve this
problem rather than accept failure and use another method.

I pass the url for the third page to the third party to redirect to
when their work is done. The problem is the snippet state is lost
after the redirect. I have tried many different things and it seems
like something like this should work.

// in the processing done before redirect to third party.
// assemble the return path url.

class Wizard extends StatefulSnippet with Logger {

def doRedirect = {
val returnPath = urlEncode(S.hostAndPath + ( link("/lastPage", () =>
redirectTo("/lastPage"), NodeSeq.Empty) \ "@href).text)

redirectTo( third_party_url +"?return=" + returnPath)
}
}

This does generate a return path like "http://localhost:8080/lastPage?
F1151306194165AHF=_" , however all state is gone after the third party
redirects back to the site, however if I don't redirect to the third
party and instead redirect the "val returnPath" I construct directly,
state is maintained.

Is it possible to resume my StatefulSnippet? Or shall I just use
something else?

Thanks to all who read and or respond.

-Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@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.

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@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.



[Lift] Resuming a Statefull Snippet.

2010-03-04 Thread andythedestroyer
Hello,

I have a simple use case where there is a 2 page form wizard then a
redirect to a third party ( for some external validation ) which
redirects back to a third and final page of the wizard.

I know I could just use snippets and SessionVars to manage this but I
have been using StatefullSnippets and would like to try to solve this
problem rather than accept failure and use another method.

I pass the url for the third page to the third party to redirect to
when their work is done. The problem is the snippet state is lost
after the redirect. I have tried many different things and it seems
like something like this should work.

// in the processing done before redirect to third party.
// assemble the return path url.

class Wizard extends StatefulSnippet with Logger {

def doRedirect = {
val returnPath = urlEncode(S.hostAndPath + ( link("/lastPage", () =>
redirectTo("/lastPage"), NodeSeq.Empty) \ "@href).text)

redirectTo( third_party_url +"?return=" + returnPath)
}
}

This does generate a return path like "http://localhost:8080/lastPage?
F1151306194165AHF=_" , however all state is gone after the third party
redirects back to the site, however if I don't redirect to the third
party and instead redirect the "val returnPath" I construct directly,
state is maintained.

Is it possible to resume my StatefulSnippet? Or shall I just use
something else?

Thanks to all who read and or respond.

-Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@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.