Packages

trait QueryStringBindable[A] extends AnyRef

Binder for query string parameters.

You can provide an implementation of QueryStringBindable[A] for any type A you want to be able to bind directly from the request query string.

For example, if you have the following type to encode pagination:

/**
 * @param index Current page index
 * @param size Number of items in a page
 */
case class Pager(index: Int, size: Int)

Play will create a Pager(5, 42) value from a query string looking like /foo?p.index=5&p.size=42 if you define an instance of QueryStringBindable[Pager] available in the implicit scope.

For example:

object Pager {
  implicit def queryStringBinder(implicit intBinder: QueryStringBindable[Int]) = new QueryStringBindable[Pager] {
    override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, Pager]] = {
      for {
        index <- intBinder.bind(key + ".index", params)
        size <- intBinder.bind(key + ".size", params)
      } yield {
        (index, size) match {
          case (Right(index), Right(size)) => Right(Pager(index, size))
          case _ => Left("Unable to bind a Pager")
        }
      }
    }
    override def unbind(key: String, pager: Pager): String = {
      intBinder.unbind(key + ".index", pager.index) + "&" + intBinder.unbind(key + ".size", pager.size)
    }
  }
}

To use it in a route, just write a type annotation aside the parameter you want to bind:

GET  /foo        controllers.foo(p: Pager)
Self Type
QueryStringBindable[A]
Annotations
@implicitNotFound("No QueryString binder found for type ${A}. Try to implement an implicit QueryStringBindable for this type.")
Source
Binders.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. QueryStringBindable
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]

    Bind a query string parameter.

    Bind a query string parameter.

    key

    Parameter key

    params

    QueryString data

    returns

    None if the parameter was not present in the query string data. Otherwise, returns Some of either Right of the parameter value, or Left of an error message if the binding failed.

  2. abstract def unbind(key: String, value: A): String

    Unbind a query string parameter.

    Unbind a query string parameter.

    key

    Parameter key

    value

    Parameter value.

    returns

    a query string fragment containing the key and its value. E.g. "foo=42"

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def javascriptUnbind: String

    Javascript function to unbind in the Javascript router.

  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. def transform[B](toB: (A) => B, toA: (B) => A): QueryStringBindable[B]

    Transform this QueryStringBindable[A] to QueryStringBindable[B]

  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped