net.liftweb.http.S

object S

object S

 extends HasParams with Loggable


An object representing the current state of the HTTP request and response. It uses the DynamicVariable construct such that each thread has its own local session info without passing a huge state construct around. The S object is initialized by LiftSession on request startup.
see
- LiftFilter
- LiftSession


Source: S.scala(44)

Nested Classes

AFuncHolder, CookieHolder, DispatchHolder, PFPromoter, RewriteHolder,

 Constructors

def this

 Fields

BinFuncHolder.. object BinFuncHolder

 extends ScalaObject
LFuncHolder.. object LFuncHolder

 extends ScalaObject
NFuncHolder.. object NFuncHolder

 extends ScalaObject
PFPromoter.. object PFPromoter

 extends ScalaObject
SFuncHolder.. object SFuncHolder

 extends ScalaObject
attr.. object attr
Used to get an attribute by its name [details]
There are several means to getting attributes:
  // Get a Box for the attribute:
  val myAttr = S.attr("test") openOr "Not found"
  // Get an attribute or return a default value:
  val myAttr = S.attr("name", "Fred")
  // Apply a transform function on the attribute value, or return an Empty:
  val pageSize = S.attr("count", _.toInt) openOr 20
  // There are also prefixed versions:
  val prefixedAttr = S.attr("prefix", "name") openOr "Not found"
   


 extends AttrHelper[Box]
attrsFlattenToMap.. def attrsFlattenToMap
Converts the S [details]
attrs to a Map[String, String]. The key of the map depends on whether the attribute is prefixed or not. Prefixed attributes have keys of the form "prefix:name", while unprefixed attributes have keys of the form "name". If you only want attributes for a specific prefix, use prefixedAttrsToMap.
see
- # prefixedAttrsToMap ( String, Map )
- # prefixedAttrsToMap ( String )
Map[String, String]
attrsToMetaData.. def attrsToMetaData
Converts S [details]
attrs attributes to a MetaData object that can be used to add attributes to one or more XML elements. Similar to prefixedAttrsToMetaData, except that it handles both prefixed and unprefixed attributes. This version of the method will use all of the currently set attributes from S.attrs. If you want to filter it, use the attrsToMetaData(String => Boolean) version, which allows you to specify a predicate function for filtering. For example, if you want all of the current attributes to be added to a div tag, you could do:
   val myDiv = (
{...}
) % S.attrsToMetaData
return
- a MetaData instance representing all attributes in S.attrs
see
- # attrsToMetaData ( String = > Boolean )
MetaData
clearHighLevelSessionDispatcher.. def clearHighLevelSessionDispatcher
Clears all custom dispatch functions from the current session [details]
See addHighLevelSessionDispatcher for an example of usage.
see
- # clearHighLevelSessionDispatcher
- LiftRules.dispatch
- # addHighLevelSessionDispatcher
- LiftRules.DispatchPF
Box[Unit]
clearSessionRewriter.. def clearSessionRewriter
Clears the per-session rewrite table [details]
See addSessionRewriter for an example of usage.
see
- # addSessionRewriter
- # removeSessionRewriter
- LiftRules.rewrite
Box[Unit]
containerRequest.. def containerRequest
The current container request
Box[HTTPRequest]
containerSession.. def containerSession
Returns the HttpSession
Box[HTTPSession]
contextPath.. def contextPath
The current context path for the deployment
String
currentAttrs.. def currentAttrs MetaData
currentAttrsToMetaData.. def currentAttrsToMetaData
Converts S [details]
attrs attributes to a MetaData object that can be used to add attributes to one or more XML elements. Similar to prefixedAttrsToMetaData, except that it handles both prefixed and unprefixed attributes. This version of the method will use all of the currently set attributes from S.attrs. If you want to filter it, use the attrsToMetaData(String => Boolean) version, which allows you to specify a predicate function for filtering. For example, if you want all of the current attributes to be added to a div tag, you could do:
   val myDiv = (
{...}
) % S.attrsToMetaData
return
- a MetaData instance representing all attributes in S.attrs
see
- # attrsToMetaData ( String = > Boolean )
MetaData
currentSnippet.. def currentSnippet Box[String]
disableTestFuncNames_?.. def disableTestFuncNames_? Boolean
formFuncName.. def formFuncName String
functionLifespan_?.. def functionLifespan_?
Returns whether functions are currently extended to the lifetime of the session [details]
return
- true if mapped functions will currently last the life of the session.
Boolean
functionMap.. def functionMap
Get a map of function name bindings that are used for form and other processing [details]
Using these bindings is considered advanced functionality.
Map[String, AFuncHolder]
get_?.. def get_?
Test the current request to see if it's a GET [details]
This is a thin wrapper on Req.get_?
return
- true if the request is a GET, false otherwise.
see
- Req.get_ ?
Boolean
highLevelSessionDispatchList.. def highLevelSessionDispatchList
Return the list of DispatchHolders set for this session [details]
see
- DispatchHolder
List[DispatchHolder]
highLevelSessionDispatcher.. def highLevelSessionDispatcher
Return a List of the LiftRules [details]
DispatchPF functions that are set for this session. See addHighLevelSessionDispatcher for an example of how these are used.
see
- # clearHighLevelSessionDispatcher
- # addHighLevelSessionDispatcher ( String, LiftRules.DispatchPF )
- # removeHighLevelSessionDispatcher ( String )
- LiftRules.DispatchPF
List[PartialFunction]
hostAndPath.. def hostAndPath
The host and path of the request up to and including the context path [details]
This does not include the template path or query string.
String
hostName.. def hostName
The hostname to which the request was sent [details]
This is taken from the "Host" HTTP header, or if that does not exist, the DNS name or IP address of the server.
String
ieMode.. def ieMode
[details]
return
- true if this response should be rendered in IE6/IE7 compatibility mode.
see
- Req.isIE6
- Req.isIE8
- LiftSession.ieMode
- Req.isIE
- LiftRules.calcIEMode
- Req.isIE7
Boolean
inStatefulScope_?.. def inStatefulScope_?
This method returns true if the S object has been initialized for our current scope [details]
If the S object has not been initialized then functionality on S will not work.
Boolean
invokedAs.. def invokedAs
Returns the 'type' S attribute [details]
This corresponds to the current Snippet's name. For example, the snippet:
  <lift:Hello.world />
   
Will return "Hello.world".
String
liftCoreResourceBundle.. def liftCoreResourceBundle
Get the lift core resource bundle for the current locale as defined by the LiftRules [details]
liftCoreResourceName varibale.
see
- LiftRules.liftCoreResourceName
Box[ResourceBundle]
locale.. def locale
Returns the Locale for this request based on the LiftRules [details]
localeCalculator method.
see
- java.util.Locale
- LiftRules.localeCalculator ( HTTPRequest )
Locale
location.. def location Box[Loc[Any]]
loggedIn_?.. def loggedIn_?
This method is a convenience accessor for LiftRules [details]
loggedInTest. You can define your own function to check to see if a user is logged in there and this will call it.
return
- the value from executing LiftRules.loggedInTest, or false if a test function is not defined.
see
- LiftRules.loggedInTest
Boolean
logger.. protected val logger Logger Loggable
post_?.. def post_?
Test the current request to see if it's a POST [details]
This is a thin wrapper over Req.post_?
return
- true if the request is a POST request, false otherwise.
Boolean
queryString.. def queryString
Returns the query string for the current request
Box[String]
receivedCookies.. def receivedCookies
[details]
return
- a List of any Cookies that have been set for this Response. If you want a specific cookie, use findCookie.
see
- # addCookie ( Cookie )
- # deleteCookie ( String )
- net.liftweb.http.provider.HTTPCookie
- # findCookie ( String )
- # deleteCookie ( Cookie )
List[HTTPCookie]
referer.. def referer
Returns the 'Referer' HTTP header attribute
Box[String]
request.. def request
Get a Req representing our current HTTP request [details]
return
- A Full(Req) if one has been initialized on the calling thread, Empty otherwise.
see
- Req
Box[Req]
resourceBundles.. def resourceBundles
Get a List of the resource bundles for the current locale [details]
The resource bundles are defined by the LiftRules.resourceNames and LiftRules.resourceBundleFactories variables.
see
- LiftRules.resourceBundleFactories
- LiftRules.resourceNames
List[ResourceBundle]
responseCookies.. def responseCookies
[details]
return
- a List of any Cookies that have been added to the response to be sent back to the user. If you want the cookies that were sent with the request, see receivedCookies.
see
- net.liftweb.http.provider.HTTPCookie
- # receivedCookies
List[HTTPCookie]
session.. def session
The current LiftSession
Box[LiftSession]
sessionRewriter.. def sessionRewriter
Return the list of RewriteHolders set for this session [details]
See addSessionRewriter for an example of how to use per-session rewrites.
see
- LiftRules # rewrite
- RewriteHolder
List[RewriteHolder]
skipDocType.. def skipDocType
When this is true, Lift will not emit a DocType definition at the start of the response content [details]
If you're sending XHTML and this is set to true, you need to include the DocType in your template.
see
- # skipDocType_ =(Boolean)
Boolean
skipXmlHeader.. def skipXmlHeader
If true, then the xml header at the beginning of the returned XHTML page will not be inserted
Boolean
templateFromTemplateAttr.. def templateFromTemplateAttr Box[NodeSeq]
timeZone.. def timeZone
Return the current timezone based on the LiftRules [details]
timeZoneCalculator method.
see
- java.util.TimeZone
- LiftRules.timeZoneCalculator ( HTTPRequest )
TimeZone
uri.. def uri
The URI of the current request (not re-written) [details]
The URI is the portion of the request URL after the context path. For example, with a context path of "myApp", Lift would return the following URIs for the given requests:
HTTP requestURI
http://foo.com/myApp/foo/bar.html/foo/bar.html
http://foo.com/myApp/test//test/
http://foo.com/myApp/item.html?id=42/item.html
If you want the full URI, including the context path, you should retrieve it from the underlying HTTPRequest. You could do something like:
     val fullURI = S.request.map(_.request.getRequestURI) openOr ("Undefined")
   
The URI may be used to provide a link back to the same page as the current request:
     bind(...,
          "selflink" -> SHtml.link(S.uri,  { () => ... }, Text("Self link")),
          ...)
   
see
- net.liftweb.http.provider.HTTPRequest.uri
- Req.uri
String
uriAndQueryString.. def uriAndQueryString Box[String]

 Methods

!=.. final def !=(arg0 : Any) Boolean Any
!=.. final def !=(arg0 : Object) Boolean AnyRef
==.. final def ==(arg0 : Object) Boolean AnyRef
==.. final def ==(arg0 : Any) Boolean Any
?.. def ?(str : String)
Get a localized string or return the original string [details]
param
str - the string to localize
return
- the localized version of the string
see
- # resourceBundles
String
?.. def ?(str : String, params : Any*)
Attempt to localize and then format the given string [details]
This uses the String.format method to format the localized string.
param
params - the var-arg parameters applied for string formatting
str - the string to localize
return
- the localized and formatted version of the string
see
- String.format
- # resourceBundles
String
??.. def ??(str : String)
Get a core lift localized string or return the original string [details]
param
str - the string to localize
return
- the localized version of the string
String
??.. def ??(str : String, params : Object*)
Get a core lift localized and formatted string or return the original string [details]
param
params - the var-arg parameters applied for string formatting
str - the string to localize
return
- the localized version of the string
String
addAnalyzer.. def addAnalyzer(f : (Box[Req], Long, List[(String, Long)]) => Any)
Add a query analyzer (passed queries for analysis or logging) [details]
The analyzer methods are executed with the request, total time to process the request, and the List of query log entries once the current request completes.
see
- # queryLog
- # logQuery
Unit
addAround.. def addAround(lw : LoanWrapper)
You can wrap the handling of an HTTP request with your own wrapper [details]
The wrapper can execute code before and after the request is processed (but still have S scope). This allows for query analysis, etc. Wrappers are chained, much like servlet filters, so you can layer processing on the request. As an example, let's look at a wrapper that opens a resource and makes it available via a RequestVar, then closes the resource when finished:
   import net.liftweb.http.{ ResourceVar,S }
   import net.liftweb.util.LoanWrapper
  
   // Where "ResourceType" is defined by you
   object myResource extends ResourceVar[ResourceType](...)
  
   class Boot  {
     def boot  {
       ...
       S.addAround(
         new LoanWrapper  {
           def apply[T](f: => T) : T =  {
             myResource(... code to open and return a resource instance ...)
             f() // This call propagates the request further down the "chain" for template processing, etc.
             myResource.is.close() // Release the resource
   }
   }
       )
       ...
   }
   }
   
see
- LoanWrapper
- # addAround ( LoanWrapper )
Unit
addAround.. def addAround(lw : List[LoanWrapper])
You can wrap the handling of an HTTP request with your own wrapper [details]
The wrapper can execute code before and after the request is processed (but still have S scope). This allows for query analysis, etc. See S.addAround(LoanWrapper) for an example. This version of the method takes a list of LoanWrappers that are applied in order.
see
- LoanWrapper
- # addAround ( LoanWrapper )
Unit
addCleanupFunc.. def addCleanupFunc(f : () => Unit)
Adds a cleanup function that will be executed at the end of the request pocessing [details]
Exceptions thrown from these functions will be swallowed, so make sure to handle any expected exceptions within your function.
param
f - The function to execute at the end of the request.
Unit
addCookie.. def addCookie(cookie : HTTPCookie)
Adds a Cookie to the List[Cookies] that will be sent with the Response [details]
If you wish to delete a Cookie as part of the Response, use the deleteCookie method. An example of adding and removing a Cookie is:
   import net.liftweb.http.provider.HTTPCookie
  
   class MySnippet  {
     final val cookieName = "Fred"
  
     def cookieDemo (xhtml : NodeSeq) : NodeSeq =  {
       var cookieVal = S.findCookie(cookieName).map(_.getvalue) openOr ""
  
       def setCookie()  {
         val cookie = HTTPCookie(cookieName, cookieVal).setMaxAge(3600) // 3600 seconds, or one hour
         S.addCookie(cookie)
   }
  
       bind("cookie", xhtml,
            "value" -> SHtml.text(cookieVal, cookieVal = _),
            "add" -> SHtml.submit("Add", setCookie)
            "remove" -> SHtml.link(S.uri, () => S.deleteCookie(cookieName), "Delete Cookie")
       )
   }
   }
   
see
- # responseCookies
- # deleteCookie ( Cookie )
- # deleteCookie ( String )
- net.liftweb.http.provider.HTTPCookie
Unit
addFunctionMap.. def addFunctionMap(name : String, value : AFuncHolder)
Associates a name with a function impersonated by AFuncHolder [details]
These are basically functions that are executed when a request contains the 'name' request parameter.
Unit
addHighLevelSessionDispatcher.. def addHighLevelSessionDispatcher(name : String, disp : PartialFunction)
Adds a dispatch function for the current session, as opposed to a global dispatch through LiftRules [details]
dispatch. An example would be if we wanted a user to be able to download a document only when logged in. First, we define a dispatch function to handle the download, specific to a given user:
   def getDocument(userId : Long)() : Box[LiftResponse] =  { ... }
   
Then, in the login/logout handling snippets, we could install and remove the custom dispatch as appropriate:
     def login(xhtml : NodeSeq) : NodeSeq =  {
       def doAuth ()  {
         ...
         if (user.loggedIn_?)  {
           S.addHighLevelSessionDispatcher("docDownload",  {
             case Req(List("download", "docs"), _, _) => getDocument(user.id)
   } )
   }
   }
  
     def logout(xhtml : NodeSeq) : NodeSeq =  {
       def doLogout ()  {
         ...
         S.removeHighLevelSessionDispatcher("docDownload")
         // or, if more than one dispatch has been installed, this is simpler
         S.clearHighLevelSessionDispatcher
   }
   }
   
It's important to note that per-session dispatch takes precedence over LiftRules.dispatch, so you can override things set there.
param
disp - The dispatch partial function
name - A name for the dispatch. This can be used to remove it later by name.
see
- LiftRules.dispatch
- # clearHighLevelSessionDispatcher
- LiftRules.DispatchPF
- # removeHighLevelSessionDispatcher
Box[Unit]
addSessionRewriter.. def addSessionRewriter(name : String, rw : PartialFunction)
Adds a per-session rewrite function [details]
This can be used if you only want a particular rewrite to be valid within a given session. Per-session rewrites take priority over rewrites set in LiftRules.rewrite, so you can use this mechanism to override global functionality. For example, you could set up a global rule to make requests for the "account profile" page go back to the home page by default:
   package bootstrap.liftweb
   ... imports ...
   class Boot  {
     def boot  {
       LiftRules.rewrite.append  {
         case RewriteRequest(ParsePath(List("profile")), _, _, _) =>
           RewriteResponse(List("index"))
   }
   }
   }
   
Then, in your login snippet, you could set up a per-session rewrite to the correct template:
   def loginSnippet (xhtml : NodeSeq) : NodeSeq =  {
     ...
     def doLogin ()  {
       ...
       S.addSessionRewriter("profile",  {
         case RewriteRequest(ParsePath(List("profile")), _, _, _) =>
           RewriteResponse(List("viewProfile"), Map("user" -> user.id))
   }
       ...
   }
     ...
   }
   
And in your logout snippet you can remove the rewrite:
     def doLogout ()  {
       S.removeSessionRewriter("profile")
       // or
       S.clearSessionRewriter
   }
   
param
name - A name for the rewrite function so that it can be replaced or deleted later. @rw The rewrite partial function
see
- # removeSessionRewriter
- LiftRules.rewrite
- # sessionRewriter
- # clearSessionRewriter
Box[Unit]
addSnippetForClass.. def addSnippetForClass(cls : String, inst : DispatchSnippet)
Register a stateful snippet for a given class name [details]
Only registers if the name is not already set.
Unit
asInstanceOf.. final def asInstanceOf[T0] T0 Any
attrs.. def attrs
Get a list of current attributes [details]
Each attribute item is a pair of (key,value). The key is an Either that depends on whether the attribute is prefixed or not. If the attribute is prefixed, the key is a Right((prefix, name)). If the attribute is unprefixed then the key is a Left(name). For example, the following table shows how various tag attributes would be represented:
Snippet Tag Parsed attrs
<lift:MySnippet testname="test" /> List((Left("testname"), "test"))
<lift:MySnippet anchor:name="test" /> List((Right(("anchor", "name")), "test"))

The prefixedAttrsToMap method provides a convenient way to retrieve only attributes with a given prefix. The prefixedAttrsToMetaData method can be used to add attributes onto an XML node

see
- # prefixedAttrsToMetaData ( String, Map )
- # prefixedAttrsToMap ( String, Map )
- # prefixedAttrsToMetaData ( String )
- # prefixedAttrsToMap ( String )
List[(Either[String, (String, String)], String)]
attrsToMetaData.. def attrsToMetaData(predicate : (String) => Boolean)
Similar to S [details]
attrsToMetaData, but lets you specify a predicate function that filters the generated MetaData. For example, if you only wanted the "id" attribute, you could do:
   val myDiv = (
{...}
) % S.attrsToMetaData(_.equalsIgnoreCase("id"))
param
predicate - The predicate function which is executed for each attribute name. If the function returns true, then the attribute is included in the MetaData.
see
- # attrsToMetaData
MetaData
buildJsonFunc.. def buildJsonFunc(f : (Any) => JsCmd)
Build a handler for incoming JSON commands [details]
param
f - - function returning a JsCmds
return
- ( JsonCall, JsCmd )
(JsonCall, JsCmd)
buildJsonFunc.. def buildJsonFunc(name : Box[String], onError : Box[JsCmd], f : (Any) => JsCmd)
Build a handler for incoming JSON commands [details]
param
f - - function returning a JsCmds
name - -- the optional name of the command (placed in a comment for testing)
return
- ( JsonCall, JsCmd )
(JsonCall, JsCmd)
buildJsonFunc.. def buildJsonFunc(onError : JsCmd, f : (Any) => JsCmd) (JsonCall, JsCmd)
callOnce.. def callOnce[T](f : => T)
If you bind functions (i [details]
e. using SHtml helpers) inside the closure passed to callOnce, after your function is invoked, it will be automatically removed from functions cache so that it cannot be invoked again.
T
clearCurrentNotices.. def clearCurrentNotices
Clears up the notices
Unit
clearFunctionMap.. def clearFunctionMap
Clears the function map [details]
potentially very destuctive... use at your own risk!
Unit
clone.. protected def clone Object AnyRef
contextFuncBuilder.. def contextFuncBuilder(f : AFuncHolder)
Wrap an AFuncHolder with the current snippet and Loc context so that for Ajax calls, the original snippets, RequestVars and Loc (location) are populated [details]
param
f - the AFuncHolder that you want to wrap with execution context
AFuncHolder
cookieValue.. def cookieValue(name : String)
Get the cookie value for the given cookie
Box[String]
createJsonFunc.. def createJsonFunc(onError : JsCmd, f : PFPromoter[JValue, JsCmd])
Build a handler for incoming JSON commands based on the new Json Parser [details]
param
f - - partial function against a returning a JsCmds
onError - -- the JavaScript to execute client-side if the request is not processed by the server
return
- ( JsonCall, JsCmd )
(JsonCall, JsCmd)
createJsonFunc.. def createJsonFunc(name : Box[String], onError : Box[JsCmd], pfp : PFPromoter[JValue, JsCmd])
Build a handler for incoming JSON commands based on the new Json Parser [details]
You can use the helpful Extractor in net.liftweb.util.JsonCommand
param
onError - -- the JavaScript to execute client-side if the request is not processed by the server
f - - partial function against a returning a JsCmds
name - -- the optional name of the command (placed in a comment for testing)
return
- ( JsonCall, JsCmd )
(JsonCall, JsCmd)
createJsonFunc.. def createJsonFunc(f : PFPromoter[JValue, JsCmd])
Build a handler for incoming JSON commands based on the new Json Parser [details]
param
f - - partial function against a returning a JsCmds
return
- ( JsonCall, JsCmd )
(JsonCall, JsCmd)
currentAttrsToMetaData.. def currentAttrsToMetaData(predicate : (String) => Boolean)
Similar to S [details]
attrsToMetaData, but lets you specify a predicate function that filters the generated MetaData. For example, if you only wanted the "id" attribute, you could do:
   val myDiv = (
{...}
) % S.attrsToMetaData(_.equalsIgnoreCase("id"))
param
predicate - The predicate function which is executed for each attribute name. If the function returns true, then the attribute is included in the MetaData.
see
- # attrsToMetaData
MetaData
deleteCookie.. def deleteCookie(cookie : HTTPCookie)
Deletes the cookie from the user's browser [details]
param
cookie - the Cookie to delete
see
- # deleteCookie ( String )
- net.liftweb.http.provider.HTTPCookie
- # addCookie ( Cookie )
Unit
deleteCookie.. def deleteCookie(name : String)
Deletes the cookie from the user's browser [details]
param
name - the name of the cookie to delete
see
- # deleteCookie ( Cookie )
- net.liftweb.http.provider.HTTPCookie
- # addCookie ( Cookie )
Unit
disableTestFuncNames.. def disableTestFuncNames[T](f : => T) T
encodeURL.. def encodeURL(url : String)
Decorates an URL with jsessionid parameter in case cookies are disabled from the container [details]
Also it appends general purpose parameters defined by LiftRules.urlDecorate
String
eq.. final def eq(arg0 : Object) Boolean AnyRef
equals.. def equals(arg0 : Any) Boolean AnyRef
error.. def error(vi : List[FieldError])
Sets an ERROR notices from a List[FieldError]
Unit
error.. def error(n : String)
Sets an ERROR notice as a plain text
Unit
error.. def error(id : String, n : NodeSeq)
Sets an ERROR notice as an XML sequence and associates it with an id
Unit
error.. def error(id : String, n : String)
Sets an ERROR notice as plain text and associates it with an id
Unit
error.. def error(n : NodeSeq)
Sets an ERROR notice as an XML sequence
Unit
errors.. def errors
Returns only ERROR notices
List[(NodeSeq, Box[String])]
finalize.. protected def finalize Unit AnyRef
findCookie.. def findCookie(name : String)
Finds a cookie with the given name that was sent in the request [details]
param
name - - the name of the cookie to find
return
- Full ( cookie ) if the cookie exists, Empty otherwise
see
- # receivedCookies
- # deleteCookie ( Cookie )
- # deleteCookie ( String )
- net.liftweb.http.provider.HTTPCookie
- # addCookie ( Cookie )
Box[HTTPCookie]
fmapFunc.. def fmapFunc[T](in : AFuncHolder)(f : (String) => T)
Maps a function with an random generated and name
T
formGroup.. def formGroup[T](group : Int)(f : => T) T
functionLifespan.. def functionLifespan[T](span : Boolean)(f : => T)
Functions that are mapped to HTML elements are, by default, garbage collected if they are not seen in the browser in the last 10 minutes (defined in LiftRules [details]
unusedFunctionsLifeTime). In some cases (e.g., JSON handlers), you may want to extend the lifespan of the functions to the lifespan of the session.
param
f - A function to execute in the context of specified span
span - If true, extend the mapped function lifetime to the life of the session
see
- LiftRules.unusedFunctionsLifeTime
T
get.. def get(what : String)
Returns the LiftSession parameter denominated by 'what' [details]
see
- # unset
- # set
- # setSessionAttribute
- # unsetSessionAttribute
- # getSessionAttribute
Box[String]
getAllNotices.. def getAllNotices
Returns the current and "old" notices
List[(Value, NodeSeq, Box[String])]
getClass.. final def getClass Class[Any] AnyRef
getDocType.. def getDocType
Returns the document type that was set for the response [details]
The default is XHTML 1.0 Transitional.
see
- DocType
- setDocType
(Boolean, Box[String])
getHeader.. def getHeader(name : String)
Returns the current set value of the given HTTP response header as a Box [details]
If you want a request header, use Req.getHeader or S.getRequestHeader.
param
name - The name of the HTTP header to retrieve
return
- A Full(value) or Empty if the header isn't set
see
- # getHeaders ( List[ ( String, String ) ] )
- # setHeader ( String, String )
- # getRequestHeader ( String )
Box[String]
getHeaders.. def getHeaders(in : List[(String, String)])
Returns the currently set HTTP response headers as a List[(String, String)] [details]
To retrieve a specific response header, use S.getHeader. If you want to get request headers (those sent by the client), use Req.getHeaders or S.getRequestHeader.
see
- # getHeader ( String )
- # getRequestHeader ( String )
- # setHeader ( String, String )
List[(String, String)]
getNotices.. def getNotices
Returns the current notices
List[(Value, NodeSeq, Box[String])]
getRequestHeader.. def getRequestHeader(name : String)
Returns the current value of the given HTTP request header as a Box [details]
This is really just a thin wrapper on Req.header(String). For response headers, see S.getHeaders, S.setHeader, or S.getHeader.
param
name - The name of the HTTP header to retrieve
return
- A Full(value) or Empty if the header isn't set
see
- # getHeader ( String )
- # getHeaders ( List[ ( String, String ) ] )
- Req # header ( String )
- # setHeader ( String, String )
Box[String]
getSessionAttribute.. def getSessionAttribute(what : String)
Returns the HttpSession parameter denominated by 'what' [details]
see
- # unset
- # set
- # setSessionAttribute
- # unsetSessionAttribute
- # get
Box[String]
hashCode.. def hashCode Int AnyRef
idMessages.. def idMessages(f : => List[(NodeSeq, Box[String])])
Returns the messages that are associated with any id [details]
Messages associated with the same id will be enlisted.
param
f - - the function that returns the messages
List[(String, List[NodeSeq])]
init.. def init[B](request : Req, session : LiftSession)(f : => B)
Initialize the current request session [details]
Generally this is handled by Lift during request processing, but this method is available in case you want to use S outside the scope of a request (standard HTTP or Comet).
param
session - the LiftSession for this request
f - Function to execute within the scope of the request and session
request - The Req instance for this request
B
initIfUninitted.. def initIfUninitted[B](session : LiftSession)(f : => B) B
isInstanceOf.. final def isInstanceOf[T0] Boolean Any
jsonFmapFunc.. def jsonFmapFunc[T](in : (Any) => JsObj)(f : (String) => T)
Maps a function with an random generated and name
T
loc.. def loc(str : String)
Localize the incoming string based on a resource bundle for the current locale [details]
The localized string is converted to an XML element if necessary via the LiftRules.localizeStringToXml function (the default behavior is to wrap it in a Text element). If the lookup fails for a given resource bundle (e.g. a null is returned), then the LiftRules.localizationLookupFailureNotice function is called with the input string and locale.
param
str - the string or ID to localize
return
- A Full box containing the localized XML or Empty if there's no way to do localization
see
- # resourceBundles
- LiftRules.localizationLookupFailureNotice
- # loc ( String, NodeSeq )
- # locale
- LiftRules.localizeStringToXml
Box[NodeSeq]
loc.. def loc(str : String, dflt : NodeSeq)
Localize the incoming string based on a resource bundle for the current locale, with a default value to to return if localization fails [details]
param
dflt - the default string to return if localization fails
str - the string or ID to localize
return
- the localized XHTML or default value
see
- # loc ( String )
NodeSeq
locateMappedSnippet.. def locateMappedSnippet(name : String) Box[(NodeSeq) => NodeSeq]
locateSnippet.. def locateSnippet(name : String)
Finds a snippet function by name [details]
see
- LiftRules.snippets
Box[(NodeSeq) => NodeSeq]
logQuery.. def logQuery(query : String, time : Long)
Log a query for the given request [details]
The query log can be tested to see if queries for the particular page rendering took too long. The query log starts empty for each new request. net.liftweb.mapper.DB.queryCollector is a method that can be used as a log function for the net.liftweb.mapper.DB.addLogFunc method to enable logging of Mapper queries. You would set it up in your bootstrap like:
   import net.liftweb.mapper.DB
   import net.liftweb.http.S
   class Boot  {
     def boot  {
       ...
       DB.addLogFunc(DB.queryCollector)
       ...
   }
   }
   
Note that the query log is simply stored as a List and is not sent to any output by default. To retrieve the List of query log items, use S.queryLog. You can also provide your own analysis function that will process the query log via S.addAnalyzer.
see
- # addAnalyzer
- net.liftweb.mapper.DB.addLogFunc
- # queryLog
Unit
mapFunc.. def mapFunc(in : AFuncHolder)
Similar with addFunctionMap but also returns the name [details]
Use fmapFunc(AFuncHolder)(String => T)
String
mapFunc.. def mapFunc(name : String, inf : AFuncHolder)
Similar with addFunctionMap but also returns the name [details]
Use fmapFunc(AFuncHolder)(String => T)
String
mapFuncToURI.. def mapFuncToURI(uri : String, f : () => Unit)
Attaches to this uri and parameter that has function f associated with [details]
When this request is submitted to server the function will be executed and then it is automatically cleaned up from functions caches.
String
mapSnippet.. def mapSnippet(name : String, func : (NodeSeq) => NodeSeq)
Associates a name with a snippet function 'func' [details]
This can be used to change a snippet mapping on a per-request basis. For example, if we have a page that we want to change behavior on based on query parameters, we could use mapSnippet to programmatically determine which snippet function to use for a given snippet in the template. Our code would look like:
  import _root_.scala.xml.{ NodeSeq,Text }
  class SnipMap  {
  def topSnippet (xhtml : NodeSeq) : NodeSeq =  {
  if (S.param("showAll").isDefined)  {
  S.mapSnippet("listing", listing)
  } else  {
  S.mapSnippet("listing",  { ignore => Text("") } )
  }
  ...
  }
  def listing(xhtml : NodeSeq) : NodeSeq =  {
  ...
  }
  
Then, your template would simply look like:
  <lift:surround with="default" at="content">
  ...
  <p><lift:SnipMap.topSnippet /></p>
  <p><lift:listing /></p>
  </lift:surround>
   
Snippets are processed in the order that they're defined in the template, so if you want to use this approach make sure that the snippet that defines the mapping comes before the snippet that is being mapped. Also note that these mappings are per-request, and are discarded after the current request is processed.
param
func - The snippet function to map to.
name - The name of the snippet that you want to map (the part after "<lift:").
Unit
mapToAttrs.. def mapToAttrs(in : Map[String, String])
Converts a Map[String, String] into a MetaData instance [details]
This can be used to add attributes to an XML element based on a map of attribute->value pairs. See prefixedAttrsToMetaData(String,Map) for an example.
param
in - The map of attributes
return
- MetaData representing the Map of attributes as unprefixed attributes.
see
- # prefixedAttrsToMetaData ( String, Map )
MetaData
messages.. def messages(f : => List[(NodeSeq, Box[String])])
Returns all messages, associated with any id or not [details]
param
f - - the function that returns the messages
List[NodeSeq]
messagesById.. def messagesById(id : String)(f : => List[(NodeSeq, Box[String])])
Returns the messages provided by list function that are associated with id [details]
param
f - - the function that returns the messages
id - - the lookup id
List[NodeSeq]
ne.. final def ne(arg0 : Object) Boolean AnyRef
noIdMessages.. def noIdMessages(f : => List[(NodeSeq, Box[String])])
Returns the messages that are not associated with any id [details]
param
f - - the function that returns the messages
List[NodeSeq]
notice.. def notice(n : String)
Sets an NOTICE notice as plain text
Unit
notice.. def notice(id : String, n : NodeSeq)
Sets an NOTICE notice as and XML sequence and associates it with an id
Unit
notice.. def notice(id : String, n : String)
Sets an NOTICE notice as plai text and associates it with an id
Unit
notice.. def notice(n : NodeSeq)
Sets an NOTICE notice as an XML sequence
Unit
notices.. def notices
Returns only NOTICE notices
List[(NodeSeq, Box[String])]
notify.. final def notify Unit AnyRef
notifyAll.. final def notifyAll Unit AnyRef
oneShot.. def oneShot[T](f : => T)
All functions created inside the oneShot scope will only be called once and their results will be cached and served again if the same function is invoked
T
overrideSnippetForClass.. def overrideSnippetForClass(cls : String, inst : DispatchSnippet)
Register a stateful snippet for a given class name [details]
The addSnippetForClass method is preferred
Unit
param.. def param(n : String)
Returns the HTTP parameter having 'n' name
Box[String]
params.. def params(n : String)
Returns all the HTTP parameters having 'n' name
List[String]
prefixedAttrsToMap.. def prefixedAttrsToMap(prefix : String, start : Map[String, String])
Returns the S attributes that are prefixed by 'prefix' parameter as a Map[String, String] that will be 'merged' with the 'start' Map [details]
param
start - the initial Map
prefix - the prefix to be matched
return
- Map[String, String]
see
- # prefixedAttrsToMap ( String )
- # prefixedAttrsToMetaData ( String, Map )
- # prefixedAttrsToMetaData ( String )
Map[String, String]
prefixedAttrsToMap.. def prefixedAttrsToMap(prefix : String)
Returns the S attributes that are prefixed by 'prefix' parameter as a Map[String, String] [details]
param
prefix - the prefix to be matched
return
- Map[String, String]
see
- # prefixedAttrsToMetaData ( String )
- # prefixedAttrsToMap ( String, Map )
- # prefixedAttrsToMetaData ( String, Map )
Map[String, String]
prefixedAttrsToMetaData.. def prefixedAttrsToMetaData(prefix : String, start : Map[String, String])

Returns the S attributes that are prefixed by 'prefix' parameter as a MetaData [details]

The start Map will be 'merged' with the Map resulted after prefix matching and the result Map will be converted to a MetaData. The MetaData can be used to add attributes back onto XML elements via Scala's '%' method. For example, if we wanted to add attributes prefixed with "anchor" to any <a> elements we create, we could do something like:

     val myLink = (...) % S.prefixedAttrsToMetaData("anchor", Map("id" -> "myAnchor"))
   
param
start - the initial Map
prefix - the prefix to be matched
return
- MetaData representing the combination of current attributes plus the start Map of attributes
see
- # prefixedAttrsToMap ( String )
- # prefixedAttrsToMetaData ( String )
- # prefixedAttrsToMap ( String, Map )
MetaData
prefixedAttrsToMetaData.. def prefixedAttrsToMetaData(prefix : String)
Similar with prefixedAttrsToMetaData(prefix: String, start: Map[String, String]) but there is no 'start' Map
MetaData
queryLog.. def queryLog
Get a list of the logged queries [details]
These log entries are added via the logQuery method, which has a more detailed explanation of usage.
see
- # addAnalyzer
- # logQuery ( String, Long )
List[(String, Long)]
redirectTo.. def redirectTo[T](where : String, func : () => Unit)
Redirects the browser to a given URL and registers a function that will be executed when the browser accesses the new URL [details]
Otherwise the function is exactly the same as S.redirectTo(String), which has example documentation. Note that if the URL that you redirect to must be part of your web application or the function won't be executed. This is because the function is only registered locally.
param
func - The function to be executed when the redirect is accessed.
where - The new URL to redirect to.
see
- # redirectTo ( String )
T
redirectTo.. def redirectTo[T](where : String)
Redirects the browser to a given URL [details]
Note that the underlying mechanism for redirects is to throw a ResponseShortcutException, so if you're doing the redirect within a try/catch block, you need to make sure to either ignore the redirect exception or rethrow it. Two possible approaches would be:
     ...
     try  {
       // your code here
       S.redirectTo(...)
   } catch  {
       case e: Exception if !e.instanceOf[net.liftweb.http.ResponseShortcutException] => ...
   }
   
or
     ...
     try  {
       // your code here
       S.redirectTo(...)
   } catch  {
       case rse: net.liftweb.http.ResponseShortcutException => throw rse
       case e: Exception => ...
   }
   
param
where - The new URL to redirect to.
see
- ResponseShortcutException
- # redirectTo ( String, ( ) => Unit)
T
removeHighLevelSessionDispatcher.. def removeHighLevelSessionDispatcher(name : String)
Removes a custom dispatch function for the current session [details]
See addHighLevelSessionDispatcher for an example of usage.
param
name - The name of the custom dispatch to be removed.
see
- # addHighLevelSessionDispatcher
- LiftRules.DispatchPF
- LiftRules.dispatch
- # clearHighLevelSessionDispatcher
Box[Unit]
removeSessionRewriter.. def removeSessionRewriter(name : String)
Removes the given per-session rewriter [details]
See addSessionRewriter for an example of usage.
see
- # addSessionRewriter
- # clearSessionRewriter
- LiftRules.rewrite
Box[Unit]
render.. def render(xhtml : NodeSeq, httpRequest : HTTPRequest) NodeSeq
respondAsync.. def respondAsync(f : => Box[LiftResponse])
Use this in DispatchPF for processing REST requests asynchronously [details]
Note that this must be called in a stateful context, therefore the S state must be a valid one.
param
f - - the user function that does the actual computation. This function takes one parameter which is the function that must be invoked for returning the actual response to the client. Note that f function is invoked asynchronously in the context of a different thread.
() => Box[LiftResponse]
runTemplate.. def runTemplate(path : List[String])
Find and process a template [details]
This can be used to load a template from within some other Lift processing, such as a snippet or view. If you just want to retrieve the XML contents of a template, use TemplateFinder.findAnyTemplate.
param
path - The path for the template that you want to process
return
- a Full Box containing the processed template, or a Failure if the template could not be found.
see
- TempalateFinder # findAnyTemplate
Box[NodeSeq]
seeOther.. def seeOther[T](where : String, func : () => Unit)
Redirects the browser to a given URL and registers a function that will be executed when the browser accesses the new URL [details]
Otherwise the function is exactly the same as S.seeOther(String), which has example documentation. Note that if the URL that you redirect to must be part of your web application or the function won't be executed. This is because the function is only registered locally.
param
func - The function to be executed when the redirect is accessed.
where - The new URL to redirect to.
see
- # seeOther ( String )
T
seeOther.. def seeOther[T](where : String)
Redirects the browser to a given URL [details]
Note that the underlying mechanism for redirects is to throw a ResponseShortcutException, so if you're doing the redirect within a try/catch block, you need to make sure to either ignore the redirect exception or rethrow it. Two possible approaches would be:
     ...
     try  {
       // your code here
       S.seeOther(...)
   } catch  {
       case e: Exception if !e.instanceOf[net.liftweb.http.ResponseShortcutException] => ...
   }
   
or
     ...
     try  {
       // your code here
       S.seeOther(...)
   } catch  {
       case rse: net.liftweb.http.ResponseShortcutException => throw rse
       case e: Exception => ...
   }
   
param
where - The new URL to redirect to.
see
- ResponseShortcutException
- # seeOther ( String, ( ) => Unit)
T
set.. def set(name : String, value : String)
Sets a LiftSession attribute [details]
see
- # unset
- # getSessionAttribute
- # setSessionAttribute
- # unsetSessionAttribute
- # get
Unit
setDocType.. def setDocType(what : Box[String])
Sets the document type for the response [details]
If this is not set, the DocType for Lift responses defaults to XHTML 1.0 Transitional.
see
- ResponseInfo.docType
- DocType
- getDocType
Unit
setHeader.. def setHeader(name : String, value : String)
Sets a HTTP response header attribute [details]
For example, you could set a "Warn" header in your response:
     ...
     S.setHeader("Warn", "The cheese is old and moldy")
     ...
   
see
- # getHeaders
Unit
setSessionAttribute.. def setSessionAttribute(name : String, value : String)
Sets a HttpSession attribute [details]
see
- # unset
- # getSessionAttribute
- # set
- # unsetSessionAttribute
- # get
Unit
setVars.. def setVars[T](attr : MetaData)(f : => T)
Temporarily adds the given attributes to the current set, then executes the given function [details]
Note that this does not modify the current attributes available via S.attr.
param
attr - The attributes to set temporarily
T
skipDocType_=.. def skipDocType_=(skip : Boolean)
Sets Lift's DocType behavior [details]
If this is set to true, Lift will not emit a DocType definition at the start of the response content. If you're sending XHTML and this is set to true, you need to include the DocType in your template.
param
skip - Set to true to prevent Lift from emitting a DocType in its response
see
- # skipDocType
Unit
skipXmlHeader_=.. def skipXmlHeader_=(in : Boolean)
Set the skipXmlHeader flag
Unit
snippetForClass.. def snippetForClass(cls : String)
Given a snippet class name, return the cached or predefined stateful snippet for that class
Box[DispatchSnippet]
stuff2ToUnpref.. implicit def stuff2ToUnpref(in : (Symbol, Any)) UnprefixedAttribute
synchronizeForSession.. def synchronizeForSession[T](f : => T)
Execute code synchronized to the current session object
T
synchronized.. final def synchronized[T0](arg0 : T0) T0 AnyRef
toLFunc.. implicit def toLFunc(in : (List[String]) => Any) AFuncHolder
toNFunc.. implicit def toNFunc(in : () => Any) AFuncHolder
toString.. def toString String AnyRef
tuple2FieldError.. implicit def tuple2FieldError(t : (FieldIdentifier, NodeSeq)) FieldError
unset.. def unset(name : String)
Removes a LiftSession attribute [details]
see
- # setSessionAttribute
- # getSessionAttribute
- # set
- # unsetSessionAttribute
- # get
Unit
unsetSessionAttribute.. def unsetSessionAttribute(name : String)
Removes a HttpSession attribute [details]
see
- # setSessionAttribute
- # getSessionAttribute
- # set
- # unset
- # get
Unit
wait.. final def wait Unit AnyRef
wait.. final def wait(arg0 : Long) Unit AnyRef
wait.. final def wait(arg0 : Long, arg1 : Int) Unit AnyRef
warning.. def warning(n : String)
Sets an WARNING notice as plain text
Unit
warning.. def warning(id : String, n : NodeSeq)
Sets an WARNING notice as an XML sequence and associates it with an id
Unit
warning.. def warning(id : String, n : String)
Sets an WARNING notice as plain text and associates it with an id
Unit
warning.. def warning(n : NodeSeq)
Sets an WARNING notice as an XML sequence
Unit
warnings.. def warnings
Returns only WARNING notices
List[(NodeSeq, Box[String])]
withAttrs.. def withAttrs[T](attrs : MetaData)(f : => T) T
Copyright (c) 2006-2010 WorldWide Conferencing, LLC. All Rights Reserved.