QueryStringBindable

play.api.mvc.QueryStringBindable
See theQueryStringBindable companion object

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)

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Parsing[A]
object bindableFloat
object bindableInt
object bindableLong
object bindableShort
object bindableUUID
object bindableChar
Show all
Self type

Members list

Value members

Abstract methods

def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]
Implicitly added by bindableJavaList

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]
Implicitly added by bindableJavaOption

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]
Implicitly added by bindableList

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]
Implicitly added by bindableOption

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]]
Implicitly added by bindableSeq

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

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

Bind a query string parameter.

Bind a query string parameter.

Value parameters

key

Parameter key

params

QueryString data

Attributes

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.

def unbind(key: String, value: A): String
Implicitly added by bindableJavaList

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

def unbind(key: String, value: A): String
Implicitly added by bindableJavaOption

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

def unbind(key: String, value: A): String
Implicitly added by bindableList

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

def unbind(key: String, value: A): String
Implicitly added by bindableOption

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

def unbind(key: String, value: A): String
Implicitly added by bindableSeq

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

def unbind(key: String, value: A): String

Unbind a query string parameter.

Unbind a query string parameter.

Value parameters

key

Parameter key

value

Parameter value.

Attributes

Returns

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

Concrete methods

Implicitly added by bindableJavaList

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

Implicitly added by bindableJavaOption

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

Implicitly added by bindableList

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

Implicitly added by bindableOption

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

Implicitly added by bindableSeq

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

Javascript function to unbind in the Javascript router.

Javascript function to unbind in the Javascript router.

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]
Implicitly added by bindableJavaList

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]
Implicitly added by bindableJavaOption

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]
Implicitly added by bindableList

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]
Implicitly added by bindableOption

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]
Implicitly added by bindableSeq

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes

def transform[B](toB: A => B, toA: B => A): QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Transform this QueryStringBindable[A] to QueryStringBindable[B]

Attributes