package data
Contains data manipulation helpers (typically HTTP form handling)
import play.api.data._ import play.api.data.Forms._ val taskForm = Form( tuple( "name" -> text(minLength = 3), "dueDate" -> date("yyyy-MM-dd"), "done" -> boolean ) )
- Source
- package.scala
- Alphabetic
- By Inheritance
- data
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
- package format
Contains the Format API used by
Form
.Contains the Format API used by
Form
.For example, to define a custom formatter:
val signedIntFormat = new Formatter[Int] { def bind(key: String, data: Map[String, String]) = { stringFormat.bind(key, data).right.flatMap { value => scala.util.control.Exception.allCatch[Int] .either(java.lang.Integer.parseInt(value)) .left.map(e => Seq(FormError(key, "error.signedNumber", Nil))) } } def unbind(key: String, value: Long) = Map( key -> ((if (value<0) "-" else "+") + value) ) }
- package validation
Contains the validation API used by
Form
.Contains the validation API used by
Form
.For example, to define a custom constraint:
val negative = Constraint[Int] { case i if i < 0 => Valid case _ => Invalid("Must be a negative number.") }
Type Members
- class DefaultFormBinding extends FormBinding
- case class Field(form: Form[_], name: String, constraints: Seq[(String, Seq[Any])], format: Option[(String, Seq[Any])], errors: Seq[FormError], value: Option[String]) extends Product with Serializable
A form field.
A form field.
- name
the field name
- constraints
the constraints associated with the field
- format
the format expected for this field
- errors
the errors associated to this field
- value
the field value, if any
- case class FieldMapping[T](key: String = "", constraints: Seq[Constraint[T]] = Nil)(implicit binder: Formatter[T]) extends Mapping[T] with Product with Serializable
A mapping for a single field.
A mapping for a single field.
- key
the field key
- constraints
the constraints associated with this field.
- case class Form[T](mapping: Mapping[T], data: Map[String, String], errors: Seq[FormError], value: Option[T]) extends Product with Serializable
Helper to manage HTML form description, submission and validation.
Helper to manage HTML form description, submission and validation.
For example, a form handling a
User
case class submission:import play.api.data._ import play.api.data.Forms._ import play.api.data.format.Formats._ val userForm = Form( mapping( "name" -> of[String], "age" -> of[Int], "email" -> of[String] )(User.apply)(User.unapply) )
- T
the type managed by this form
- mapping
the form mapping, which describes all form fields
- data
the current form data, used to display the form
- errors
the collection of errors associated with this form
- value
a concrete value of type
T
if the form submission was successful
- trait FormBinding extends AnyRef
- case class FormError(key: String, messages: Seq[String], args: Seq[Any] = Nil) extends Product with Serializable
A form error.
A form error.
- key
The error key (should be associated with a field using the same key).
- messages
The form message (often a simple message key needing to be translated), if more than one message is passed the last one will be used.
- args
Arguments used to format the message.
- case class FormJsonExpansionTooDeep(limit: Int) extends RuntimeException with NoStackTrace with Product with Serializable
- case class FormJsonExpansionTooLarge(limit: Long) extends RuntimeException with NoStackTrace with Product with Serializable
- trait Mapping[T] extends AnyRef
A mapping is a two-way binder to handle a form field.
- trait ObjectMapping extends AnyRef
Common helper methods for all object mappings - mappings including several fields.
- class ObjectMapping1[R, A1] extends Mapping[R] with ObjectMapping
- class ObjectMapping10[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10] extends Mapping[R] with ObjectMapping
- class ObjectMapping11[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11] extends Mapping[R] with ObjectMapping
- class ObjectMapping12[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12] extends Mapping[R] with ObjectMapping
- class ObjectMapping13[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13] extends Mapping[R] with ObjectMapping
- class ObjectMapping14[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14] extends Mapping[R] with ObjectMapping
- class ObjectMapping15[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15] extends Mapping[R] with ObjectMapping
- class ObjectMapping16[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16] extends Mapping[R] with ObjectMapping
- class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17] extends Mapping[R] with ObjectMapping
- class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18] extends Mapping[R] with ObjectMapping
- class ObjectMapping19[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19] extends Mapping[R] with ObjectMapping
- class ObjectMapping2[R, A1, A2] extends Mapping[R] with ObjectMapping
- class ObjectMapping20[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20] extends Mapping[R] with ObjectMapping
- class ObjectMapping21[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21] extends Mapping[R] with ObjectMapping
- class ObjectMapping22[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22] extends Mapping[R] with ObjectMapping
- class ObjectMapping3[R, A1, A2, A3] extends Mapping[R] with ObjectMapping
- class ObjectMapping4[R, A1, A2, A3, A4] extends Mapping[R] with ObjectMapping
- class ObjectMapping5[R, A1, A2, A3, A4, A5] extends Mapping[R] with ObjectMapping
- class ObjectMapping6[R, A1, A2, A3, A4, A5, A6] extends Mapping[R] with ObjectMapping
- class ObjectMapping7[R, A1, A2, A3, A4, A5, A6, A7] extends Mapping[R] with ObjectMapping
- class ObjectMapping8[R, A1, A2, A3, A4, A5, A6, A7, A8] extends Mapping[R] with ObjectMapping
- class ObjectMapping9[R, A1, A2, A3, A4, A5, A6, A7, A8, A9] extends Mapping[R] with ObjectMapping
- case class OptionalMapping[T](wrapped: Mapping[T], constraints: Seq[Constraint[Option[T]]] = Nil) extends Mapping[Option[T]] with Product with Serializable
A mapping for optional elements
A mapping for optional elements
- wrapped
the wrapped mapping
- case class RepeatedMapping[T](wrapped: Mapping[T], key: String = "", constraints: Seq[Constraint[List[T]]] = Nil) extends Mapping[List[T]] with Product with Serializable
A mapping for repeated elements.
A mapping for repeated elements.
- wrapped
The wrapped mapping
- case class WrappedMapping[A, B](wrapped: Mapping[A], f1: (A) => B, f2: (B) => A, additionalConstraints: Seq[Constraint[B]] = Nil) extends Mapping[B] with Product with Serializable
A mapping wrapping another existing mapping with transformation functions.
A mapping wrapping another existing mapping with transformation functions.
- wrapped
Existing wrapped mapping
- f1
Transformation function from A to B
- f2
Transformation function from B to A
- additionalConstraints
Additional constraints of type B
Value Members
- object Form extends Serializable
Provides a set of operations for creating
Form
values. - object FormBinding
- object FormError extends Serializable
- object Forms
Contains data manipulation helpers (typically HTTP form handling)
Contains data manipulation helpers (typically HTTP form handling)
import play.api.data._ import play.api.data.Forms._ val taskForm = Form( of(Task.apply _, Task.unapply _)( "name" -> text(minLength = 3), "dueDate" -> date("yyyy-MM-dd"), "done" -> boolean ) )
- object JodaForms
- object RepeatedMapping extends Serializable
Provides a set of operations related to
RepeatedMapping
values.