play.api.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
)
)
Attributes
Members list
Packages
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).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)
)
}
Attributes
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.")
}
Attributes
Type members
Classlikes
Attributes
- Supertypes
A form field.
A form field.
Value parameters
- constraints
-
the constraints associated with the field
- errors
-
the errors associated to this field
- format
-
the format expected for this field
- name
-
the field name
- value
-
the field value, if any
Attributes
- Supertypes
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)
)
Type parameters
- T
-
the type managed by this form
Value parameters
- data
-
the current form data, used to display the form
- errors
-
the collection of errors associated with this form
- mapping
-
the form mapping, which describes all form fields
- value
-
a concrete value of type
Tif the form submission was successful
Attributes
- Companion
- object
- Supertypes
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class DefaultFormBinding
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FormBinding.type
A form error.
A form error.
Value parameters
- args
-
Arguments used to format the message.
- 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.
Attributes
- Companion
- object
- Supertypes
Attributes
- Supertypes
-
trait Producttrait Equalstrait NoStackTraceclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
trait Producttrait Equalstrait NoStackTraceclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
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
)
)
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Forms.type
A mapping is a two-way binder to handle a form field.
A mapping is a two-way binder to handle a form field.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class FieldMapping[T]class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17]class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18]class ObjectMapping19[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19]class ObjectMapping20[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20]class ObjectMapping21[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21]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]class OptionalMapping[T]class RepeatedMapping[T]Show all
- Self type
-
Mapping[T]
Common helper methods for all object mappings - mappings including several fields.
Common helper methods for all object mappings - mappings including several fields.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class ObjectMapping17[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17]class ObjectMapping18[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18]class ObjectMapping19[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19]class ObjectMapping20[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20]class ObjectMapping21[R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21]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]Show all
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Attributes
- Supertypes
Provides a set of operations related to RepeatedMapping values.
Provides a set of operations related to RepeatedMapping values.
Attributes
- Companion
- class
- Supertypes
- Self type
-
RepeatedMapping.type
A mapping wrapping another existing mapping with transformation functions.
A mapping wrapping another existing mapping with transformation functions.
Value parameters
- additionalConstraints
-
Additional constraints of type B
- f1
-
Transformation function from A to B
- f2
-
Transformation function from B to A
- wrapped
-
Existing wrapped mapping
Attributes
- Supertypes