Object

net.liftweb.http

Bindings

Related Doc: package http

Permalink

object Bindings

A collection of types and implicit transformations used to allow composition of page elements based upon the types of rendered objects.

In Lift, a "snippet" is a function from NodeSeq => NodeSeq, where the argument to the function is a template, and the result is a fragment of a page to be rendered. Of course, this is a bit of an abbreviation; the snippet function also has an argument which is the application state made available from S. A DataBinding[T] is very similar in this respect; it is a function from some piece of information of type T to a function from NodeSeq => NodeSeq. Since DataBinding is strongly typed with respect to the type of information being rendered, DataBinding instances are ideal for the rendering of objects that is used to build up snippets. For example:

import net.liftweb.http.Bindings._

case class MyClass(str: String, i: Int, other: MyOtherClass)
case class MyOtherClass(foo: String)

trait MyClassBinding extends DataBinding[MyClass] {
  implicit val otherBinding: DataBinding[MyOtherClass]

  override def apply(entity: MyClass) = (xhtml: NodeSeq) => {
    val otherTemplate = chooseTemplate("myclass", "other", xhtml)
    bind(
      "myclass", xhtml,
      "str" -> Text("#" + entity.str + "#"),
      "i" -> Text(entity.i.toString),
      "other" -> entity.other.bind(otherTemplate)
    )
  }

}

object myOtherClassBinding extends DataBinding[MyOtherClass] {
  override def apply(other: MyOtherClass) = (xhtml: NodeSeq) => {
    bind("other", xhtml, "foo" -> Text("%" + other.foo + "%"))
  }
}

object MyClassConcreteBinding extends MyClassBinding {
  override val otherBinding = myOtherClassBinding
}

In this example, two classes and their associated bindings are constructed; the first binding for MyClass is abstract, needing a specific instance of DataBinding[MyOtherClass] to enable the implicit conversion needed to render the contained MyOtherClass instance. A subtemplate is selected, and the call to other.bind both necessitates the implicit conversion to a Bindings.Binder instance and applies the appropriate formatting. You can see how this usage keeps the concerns of the view and the model nicely separated, while allowing composition over object graphs.

Please see the tests, as well as this blog post for additional details.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Bindings
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. case class Binder(binding: Binding) extends Product with Serializable

    Permalink

    A decorator for a binding function that allows it to be called as bind() rather than apply().

    A decorator for a binding function that allows it to be called as bind() rather than apply(). This class also provides facilities for binding to a specific template

  2. type Binding = (NodeSeq) ⇒ NodeSeq

    Permalink
  3. type DataBinding[T] = (T) ⇒ (NodeSeq) ⇒ NodeSeq

    Permalink

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. object EmptyBinding extends Binding

    Permalink

    Bind any input value to the empty NodeSeq.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. implicit def binder(binding: Binding): Binder

    Permalink

    Wrap the specified Binding (a function from NodeSeq => NodeSeq) in a Binder so that it can be applied using Binder's bind methods.

  7. implicit def binder[T](t: T)(implicit binding: DataBinding[T]): Binder

    Permalink

    Implicitly convert the specified object to a binder for that object if a DataBinding for that object's type is available in implicit scope.

    Implicitly convert the specified object to a binder for that object if a DataBinding for that object's type is available in implicit scope. This essentially adds a bind() method to an object if an appropriate implicit DataBinding is available.

  8. def clone(): AnyRef

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

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

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

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

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

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

    Permalink
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped