That totally clears it up. Thanks so much. On Jan 28, 11:08 am, Naftoli Gugenheim <[email protected]> wrote: > In request 1, the page is rendered the first time and registers form > functions. In request 2--the result of submitting--they are executed, and > later the form is rendered again. > When the functions are executed, they can capture references from request 1. > If they reference a field or local variable they will use the instance of the > snippet used in request 1. > However when request 2 renders it uses a new snippet instance. So if it is to > render based on information submitted there has to be a way to bridge the two > requests. > One option is, in the submit function which sees snippet instance 1 but > occurs in request 2, set a RequestVar. RequestVars "transcend" the snippet > instance that defines, and retain their request-unique value across > instances. Thus if the submit function sets a RequestVar in snippet instance > 1, despite the fact that the form is rendered via instance 2, instance 2's > RequestVar has the same value. > Another option is StatefulSnippet, which reuses the same instance for the > next request, thus eliminating the problem. > > ------------------------------------- > > tommycli<[email protected]> wrote: > > What do you mean these functions are called only on submit? Is that > when the POST goes through and the page is rendered again? > > On Jan 27, 1:57 am, Adam Warski <[email protected]> wrote: > > > Hello, > > > > What's the purpose of RequestVars and StatefulSnippet? I thought the > > > values were retained anyway through POST. That is, on submit, the > > > functions "desc = _" and "amount = _" were executed and the so the > > > state was kept... > > > > Are those functions only executed after the bind is complete? There > > > must be something I'm missing here. > > > The functions are called after form submission, and the variable "desc" and > > "amount" will be updated. However those variables will belong to the > > original method call. So when the page is re-rendered (e.g. because of > > validation errors), the "add" method will be called again, and fresh > > variables will be created. So the values won't be retained. If you want to > > keep the values between updating and re-rendering, you need something more > > global, like a RequestVar or a StatefulSnippet. > > > -- > > Adam Warskihttp://www.warski.orghttp://www.softwaremill.eu > > -- > You received this message because you are subscribed to the Google Groups > "Lift" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
