Thanks, Derek. I read the updated PDF version of the book on "The Lift Book" group. I think it looks good. I think an example with redirectTo may be better than link. Also, personally, I'm not sure if I understand StatefulSnippet now. It doesn't seem like you can mix the two. I updated my code to no longer use StatefulSnippet and to just use requestVars and the S.redirectTo with state function. I now use RequestVars to hold my form values for error validation. I also read these same values on the redirected page to confirm the values back to the user, such as "you searched for 'query'".
On Apr 18, 8:41 pm, Derek Chen-Becker <dchenbec...@gmail.com> wrote: > OK, I just added some more explanation on passing state between snippets to > section 3.15 in the book. I just uploaded a new PDF. When you have a chance > could you look at it and let me know if that makes sense? Also, I wasn't > sure if this should be a separate section ("Passing Data Between Snippets" ? > ) or not. Thoughts? > > Derek > > On Sat, Apr 18, 2009 at 6:08 PM, Derek Chen-Becker > <dchenbec...@gmail.com>wrote: > > > A RequestVar is only "live" for the duration of the request, and a > > redirectTo ends up sending a 307 temp redirect to the browser, which results > > in a new request. S.redirectTo does have an overload that allows you to pass > > a function that will be called when the redirected request is handled. Some > > skeleton code that uses this would look like: > > > ... > > object myVar extends RequestVar[String]("") > > > def mySnippet (...) ... { > > def processSubmit () { > > ... > > val currentMyVar = myVar.is > > S.redirectTo("/newPage", () => myVar(currentMyVar)) > > } > > ... > > } > > > Notice that we need to introduce a "capture" val to hold the current value > > so that the closure function can re-set it when the redirect is processed. > > We briefly discuss this in the book, but I'll see about adding a more > > concrete example that discusses the approaches to passing state around > > between snippets. > > > Derek > > > On Sat, Apr 18, 2009 at 3:23 PM, bradford <fingerm...@gmail.com> wrote: > > >> Thanks, Tim. I worked around that issue. > > >> I would still like to know whether or not it's possible have > >> RequestVars carry over to the redirected page. I'm attaching a > >> modified demo. If I use just a var, it will maintain the state. If I > >> use RequestVar, it won't transfer the state. > > >> Well.. I couldn't find the attach button in Google Groups. Here's the > >> pasted code: (a modification of the Test.scala file found here: > > >>http://groups.google.com/group/liftweb/browse_thread/thread/db1e4631a... > >> ). > > >> package com.foo.snippet > > >> import scala.xml.{NodeSeq,Text} > > >> import net.liftweb.http._ > >> import net.liftweb.util.Helpers > >> import S._ > >> import Helpers._ > > >> class TestSnippet extends StatefulSnippet { > >> val dispatch : DispatchIt = { > >> case "add" => add _ > >> case "show" => show _ > >> } > > >> object name extends RequestVar("empty") > > >> def add (xhtml : NodeSeq) : NodeSeq = { > >> def doSubmit () = { > >> println("Name = " + name) > >> this.redirectTo("/show") > >> } > > >> bind("form", xhtml, > >> "name" -> SHtml.text(name.is, name(_)), > >> "submit" -> SHtml.submit("Add", doSubmit)) > >> } > > >> def show (xhtml : NodeSeq) : NodeSeq = { > >> bind("display", xhtml, "name" -> Text(name.is)) > >> } > >> } > > >> On Apr 18, 2:18 pm, Timothy Perrett <timo...@getintheloop.eu> wrote: > >> > Its talking about Hibernate session, not lift session. Perhaps you have > >> a > >> > detached model or something your trying to work on? > > >> > Cheers, Tim > > >> > On 18/04/2009 19:08, "bradford" <fingerm...@gmail.com> wrote: > > >> > > no session or session was > >> > > closed > > >> > > I'll look into this some more. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---