Lift Web Framework

JSON Samples



Here's the code:

class Json {
  object json extends JsonHandler {
    def apply(in: Any): JsCmd =
    SetHtml("json_result", in match {
        case JsonCmd("show", _, p: String, _) => Text(p)
        case JsonCmd("textile", _, p: String, _) =>
          TextileParser.toHtml(p, Empty)
        case JsonCmd("count", _, p: String, _) => Text(p.length+" Characters")
        case x => <b>Problem... didn't handle JSON message {x}</b>
      })
  }

  def sample(in: NodeSeq): NodeSeq =
  bind("json", in,
       "script" -> Script(json.jsCmd),
       AttrBindParam("onclick",
                     Text(json.call(ElemById("json_select")~>Value,
                                    ElemById("json_question")~>Value).toJsCmd),
                     "onclick"))
}

Lift is Copyright 2007-2010 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.
Lift version 2.3 built on Tue Apr 05 13:24:00 PDT 2011.
Stats: Total Memory: 502,792,192 Free Memory: 453,505,832 Open Sessions: 143
Updated At: Sat Feb 04 09:38:51 PST 2012 Started At: Thu Jul 07 11:17:57 PDT 2011