Trait/Object

play.api.mvc

PathBindable

Related Docs: object PathBindable | package mvc

Permalink

trait PathBindable[A] extends AnyRef

Binder for URL path parameters.

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

For example, given this class definition:

case class User(id: Int, name: String, age: Int)

You can define a binder retrieving a User instance from its id, useable like the following:

// In your routes:
// GET  /show/:user      controllers.Application.show(user)
// For example: /show/42

object Application extends Controller {
  def show(user: User) = Action {
    ...
  }
}

The definition of binder can look like the following:

object User {
  implicit def pathBinder(implicit intBinder: PathBindable[Int]) = new PathBindable[User] {
    override def bind(key: String, value: String): Either[String, User] = {
      for {
        id <- intBinder.bind(key, value).right
        user <- User.findById(id).toRight("User not found").right
      } yield user
    }
    override def unbind(key: String, user: User): String = {
      intBinder.unbind(key, user.id)
    }
  }
}
Self Type
PathBindable[A]
Annotations
@implicitNotFound( ... )
Source
Binders.scala
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. PathBindable
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def bind(key: String, value: String): Either[String, A]

    Permalink

    Bind an URL path parameter.

    Bind an URL path parameter.

    key

    Parameter key

    value

    The value as String (extracted from the URL path)

    returns

    Right of the value or Left of an error message if the binding failed

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

    Permalink

    Unbind a URL path parameter.

    Unbind a URL path parameter.

    key

    Parameter key

    value

    Parameter value.

Concrete 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. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

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

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

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

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

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

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

    Permalink
    Definition Classes
    Any
  12. def javascriptUnbind: String

    Permalink

    Javascript function to unbind in the Javascript router.

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  18. def transform[B](toB: (A) ⇒ B, toA: (B) ⇒ A): PathBindable[B]

    Permalink

    Transform this PathBinding[A] to PathBinding[B]

  19. final def wait(): Unit

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped