net.liftweb.http

StatefulSnippet

trait StatefulSnippet extends DispatchSnippet

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

}

Linear Supertypes
DispatchSnippet, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. StatefulSnippet
  2. DispatchSnippet
  3. AnyRef
  4. Any
Visibility
  1. Public
  2. All

Type Members

  1. type DispatchIt = PartialFunction[String, (NodeSeq) ⇒ NodeSeq]

    Definition Classes
    DispatchSnippet

Abstract Value Members

  1. abstract def dispatch: DispatchIt

    Definition Classes
    DispatchSnippet

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def addName(name: String): Unit

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  12. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. def link(to: String, func: () ⇒ Any, body: NodeSeq, attrs: ElemAttr*): Elem

    create an anchor tag around a body

    create an anchor tag around a body

    to

    - the target

    func

    - the function to invoke when the link is clicked

    body

    - the NodeSeq to wrap in the anchor tag

    attrs

    - the (optional) attributes for the HTML element

  16. def names: Set[String]

  17. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  20. def redirectTo(where: String): Nothing

    Redirect to another page, but make sure this StatefulSnippet is registered on that page so the state continues on the new page

  21. def registerThisSnippet(): Unit

  22. def seeOther(where: String): Nothing

    See Other to another page, but make sure this StatefulSnippet is registered on that page so the state continues on the new page

  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  24. def toString(): String

    Definition Classes
    AnyRef → Any
  25. def unregisterThisSnippet(): Unit

  26. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  27. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  28. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from DispatchSnippet

Inherited from AnyRef

Inherited from Any