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 }
- Alphabetic
- By Inheritance
- StatefulSnippet
- DispatchSnippet
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
type
DispatchIt = PartialFunction[String, (NodeSeq) ⇒ NodeSeq]
- Definition Classes
- DispatchSnippet
Abstract Value Members
-
abstract
def
dispatch: DispatchIt
- Definition Classes
- DispatchSnippet
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addName(name: String): Unit
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
link(to: String, func: () ⇒ Any, body: NodeSeq, attrs: SHtml.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
- def names: Set[String]
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
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
- def registerThisSnippet(): Unit
-
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
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
- def unregisterThisSnippet(): Unit
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )