net.liftweb.http.StatefulSnippet

trait StatefulSnippet

trait StatefulSnippet

 extends DispatchSnippet with ScalaObject


The same StatefulSnippet instance is used across a given page rendering.
If the StatefulSnippet is used to render a form, a hidden field is added to the form that causes the same instance to be used on the page that is the target of the form submission.
If you want to keep the same snippet for a page rendered via a link (<a href...>) use the StatefulSnippet.link method to create the link. This will cause the registerThisSnippet method to be called and the same instance will be used on the target page.
 class CountGame extends StatefulSnippet  {
  val dispatch: DispatchIt =  {
    case "run" => run _
 }

  def run(xhtml: NodeSeq): NodeSeq =  {
    if (lastGuess == number)  {
      bind("count", chooseTemplate("choose", "win", xhtml), "number" --> number, "count" --> count)
 } else  {
      bind("count", chooseTemplate("choose", "guess", xhtml),
        "input" --> text("", guess _),
        "last" --> lastGuess.map(v => if (v < number) v+" is low" else v+"is high").openOr("Make first Guess")
      )
 }

  private def guess(in: String)  {
    count += 1
    lastGuess = Full(toInt(in))
 }

  private val number = 1 + randomInt(100)
  private var lastGuess: Box[Int] = Empty
  private var count = 0

 }
 


Source: StatefulSnippet.scala(65)

 Fields

dispatch.. abstract def dispatch PartialFunction DispatchSnippet
names.. def names Set[String]

 Methods

!=.. final def !=(arg0 : Object) Boolean AnyRef
!=.. final def !=(arg0 : Any) Boolean Any
==.. final def ==(arg0 : Any) Boolean Any
==.. final def ==(arg0 : Object) Boolean AnyRef
addName.. def addName(name : String) Unit
asInstanceOf.. final def asInstanceOf[T0] T0 Any
clone.. protected def clone Object AnyRef
eq.. final def eq(arg0 : Object) Boolean AnyRef
equals.. def equals(arg0 : Any) Boolean AnyRef
finalize.. protected def finalize Unit AnyRef
getClass.. final def getClass Class[Any] AnyRef
hashCode.. def hashCode Int AnyRef
isInstanceOf.. final def isInstanceOf[T0] Boolean Any
link.. def link(to : String, func : () => Any, body : NodeSeq)
create an anchor tag around a body [details]
param
body - - the NodeSeq to wrap in the anchor tag
func - - the function to invoke when the link is clicked
Elem
ne.. final def ne(arg0 : Object) Boolean AnyRef
notify.. final def notify Unit AnyRef
notifyAll.. final def notifyAll Unit AnyRef
redirectTo.. def redirectTo(where : String) Nothing
registerThisSnippet.. def registerThisSnippet Unit
synchronized.. final def synchronized[T0](arg0 : T0) T0 AnyRef
toString.. def toString String AnyRef
unregisterThisSnippet.. def unregisterThisSnippet Unit
wait.. final def wait(arg0 : Long, arg1 : Int) Unit AnyRef
wait.. final def wait Unit AnyRef
wait.. final def wait(arg0 : Long) Unit AnyRef
Copyright (c) 2006-2010 WorldWide Conferencing, LLC. All Rights Reserved.