Skip to content

Commit

Permalink
Closes lift#1070. Use the Lift-JSON package for client-server JSON calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dpp committed Feb 11, 2012
1 parent 2adfb8b commit 93011cf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions web/webkit/src/main/scala/net/liftweb/http/SHtml.scala
Expand Up @@ -26,6 +26,7 @@ import http.js.AjaxInfo
import JE._
import JsCmds._
import scala.xml._
import json._

class SHtmlJBridge {
def sHtml = SHtml
Expand Down Expand Up @@ -169,6 +170,34 @@ trait SHtml {
def ajaxCall(jsCalcValue: JsExp, jsContext: JsContext, func: String => JsCmd): (String, JsExp) =
ajaxCall_*(jsCalcValue, jsContext, SFuncHolder(func))

/**
* Build a JavaScript function that will perform a JSON call based on a value calculated in JavaScript.
* This method uses the Lift-JSON package rather than the old, slow, not-typed JSONParser. This is the preferred
* way to do client to server JSON calls.
*
* @param jsCalcValue the JavaScript to calculate the value to be sent to the server
* @param func the function to call when the data is sent
*
* @return the function ID and JavaScript that makes the call
*/
def ljsonCall(jsCalcValue: JsExp, func: JsonAST.JValue => JsCmd): (String, JsExp) =
jsonCall_*(jsCalcValue, SFuncHolder(s => parseOpt(s).map(func) getOrElse Noop))

/**
* Build a JavaScript function that will perform a JSON call based on a value calculated in JavaScript.
* This method uses the Lift-JSON package rather than the old, slow, not-typed JSONParser. This is the preferred
* way to do client to server JSON calls.
*
* @param jsCalcValue the JavaScript to calculate the value to be sent to the server
* @param jsContext the context instance that defines JavaScript to be executed on call success or failure
* @param func the function to call when the data is sent
*
* @return the function ID and JavaScript that makes the call
*/
def ljsonCall(jsCalcValue: JsExp, jsContext: JsContext, func: JsonAST.JValue => JsCmd): (String, JsExp) =
jsonCall_*(jsCalcValue, jsContext, SFuncHolder(s => parseOpt(s).map(func) getOrElse Noop))


/**
* Build a JavaScript function that will perform a JSON call based on a value calculated in JavaScript
*
Expand All @@ -177,6 +206,7 @@ trait SHtml {
*
* @return the function ID and JavaScript that makes the call
*/
@scala.deprecated("Use ljsonCall")
def jsonCall(jsCalcValue: JsExp, func: Any => JsCmd): (String, JsExp) =
jsonCall_*(jsCalcValue, SFuncHolder(s => JSONParser.parse(s).map(func) openOr Noop))

Expand All @@ -189,6 +219,7 @@ trait SHtml {
*
* @return the function ID and JavaScript that makes the call
*/
@scala.deprecated("Use ljsonCall")
def jsonCall(jsCalcValue: JsExp, jsContext: JsContext, func: Any => JsCmd): (String, JsExp) =
jsonCall_*(jsCalcValue, jsContext, SFuncHolder(s => JSONParser.parse(s).map(func) openOr Noop))

Expand Down

0 comments on commit 93011cf

Please sign in to comment.