I've subclassed JsonHandler:
abstract class MyJsonHandler extends JsonHandler {
private def handlers: (JsonCall, JsCmd) =
S.buildJsonFunc(this.apply)
override def call: JsonCall = handlers._1
override def jsCmd: JsCmd = handlers._2
}
I think that should do what you're suggesting. My handler object now
subclasses MyJsonHandler. The problem now, is that the form submission
results in creating a new snippet. Because of the captured val is
calculated from a request param and this param isn't available any
more (it's just there in the request that sets up the page) it
crashes.
The code in short:
class MySnippet {
val value = S.param("param").open_! // the actual code is different,
just to show that value relies on a req param
def head = ...
def form(xhtml: NodeSeq): NodeSeq = jsonForm(jsonHandler, xhtml)
object jsonHandler extends MyJsonHandler {
def apply(in: Any): JsCmd = {
// access value
}
}
}
- Chris
On 11 Feb., 00:50, David Pollak <[email protected]> wrote:
> On Wed, Feb 10, 2010 at 2:47 PM, ced <[email protected]> wrote:
> > Hi everybody,
>
> > I'm having a JsonHandler object inside a snippet and I want to access
> > some vals from to enclosing snippet. But unfortunately this doesn't
> > work, because it seems that there is just one single instance per
> > session and class name maintained by Lift. Having a fresh handler per
> > snippet would let me easily capture some state from the enclosing
> > snippet instance, but as the same JsonHandler gets reused in setting
> > up the Javascript for callback, this is not working.
>
> > Is there a way to remove the registered handler from the session?
> > LiftSession.set and unset aren't accessible for the outside world. Or
> > to enforce to have a new handler everytime?
>
> > I'm using Lift 1.1-M8.
>
> If you use this:
>
> val (call: JsonCall, jsCmd: JsCmd) = S.buildJsonFunc{
> case ... => ...
>
> }
>
> You'll get a new JSON Handler, closed over the variables in your snippet for
> each new instance of your snippet.
>
> Is that what you're looking for?
>
> > Thanks for any ideas,
> > Chris
>
> > --
> > 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]<liftweb%[email protected]
> > >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://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 [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.