Skip to content

Instantly share code, notes, and snippets.

@tjweir
Created October 30, 2008 12:19
Show Gist options
  • Save tjweir/20980 to your computer and use it in GitHub Desktop.
Save tjweir/20980 to your computer and use it in GitHub Desktop.
package com.quotelibrary.snippet
import _root_.net.liftweb.http._
import S._
import SHtml._
import js._
import JsCmds._
import JE._
import _root_.net.liftweb.util._
import Helpers._
import _root_.scala.xml._
class Json {
object json extends JsonHandler {
def apply(in: Any): JsCmd =
SetHtml("json_result", in match {
case JsonCmd("show", _, p: String, _) => Text(in.toString)
case JsonCmd("count", _, p: String, _) => Text(p.length+" Characters")
case x => <b>Problem... didn't handle JSON message {x}</b>
})
}
def sample = {
<span>
{Script(json.jsCmd)}
<textarea id="json_question" rows="4" cols="50"></textarea>
<textarea id="json_question2" rows="4" cols="50"></textarea>
<br />
<select id="json_select">
<option value="show">Show</option>
<option value="textile">Show in Textile</option>
<option value="count">Count Characters</option>
<option value="error">Show an error</option>
</select>
<br />
<button onclick={json.call(ElemById("json_select")~>Value,
(Str("json_question:") + ElemById("json_question")~>Value + Str(",") + Str("json_question2:") + ElemById("json_question2")~>Value)).toJsCmd}>Click Me</button>
<div id="json_result"></div>
</span>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment