本文整理汇总了Scala中play.api.data.Mapping类的典型用法代码示例。如果您正苦于以下问题:Scala Mapping类的具体用法?Scala Mapping怎么用?Scala Mapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mapping类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: limit
//设置package包名称以及导入依赖的类
package com.github.stonexx.play.data
package forms
import com.github.stonexx.scala.data.Limit
import play.api.data.Forms.{optional, mapping}
import play.api.data.Mapping
trait LimitForms {
def limit[T](implicit m: Mapping[T]): Mapping[Limit[T]] = mapping(
"from" -> optional(m),
"to" -> optional(m),
"eq" -> optional(m)
)(
(from, to, eq) => Limit(from orElse eq, to orElse eq)
)(
limit => Option(limit.from, limit.to, limit.from.filter(limit.to.contains))
)
}
开发者ID:stonexx,项目名称:utils,代码行数:21,代码来源:LimitForms.scala
示例2: ExtendedForm
//设置package包名称以及导入依赖的类
package it.agilelab.bigdata.wasp.web.forms
import play.api.data.Form
import play.api.data.FormError
import play.api.data.Mapping
case class ExtendedForm[T](mapping : Mapping[T], extendedValidation : Form[T] => Seq[(String, String)]) {
def bind(data : Map[String, String]) : Form[T] = evaluateAdditionalErrors(form.bind(data))
def bind(data : play.api.libs.json.JsValue) : Form[T] = evaluateAdditionalErrors(form.bind(data))
def bindFromRequest()(implicit request : play.api.mvc.Request[_]) : Form[T] = evaluateAdditionalErrors(form.bindFromRequest())
def bindFromRequest(data : Map[String, Seq[String]]) : Form[T] = evaluateAdditionalErrors(form.bindFromRequest(data))
def evaluateAdditionalErrors(form : Form[T]) = {
val additionalErrors = extendedValidation(form).map(t => FormError(t._1, t._2))
val addedKeys = additionalErrors.map(e => e.key).toSet
val overwrittenErrors = form.errors.filter(e => addedKeys.contains(e.key))
Form(form.mapping, form.data, form.errors.diff(overwrittenErrors) ++ additionalErrors, form.value)
}
protected val form = Form(mapping, Map(), Nil, None)
}
开发者ID:agile-lab-dev,项目名称:wasp,代码行数:23,代码来源:ExtendedForm.scala
示例3: FormDataLogin
//设置package包名称以及导入依赖的类
package models
import play.api.data.{Mapping, Form}
import play.api.data.Forms._
case class FormDataLogin(email: String, password: String)
case class FormDataAccount(name:String, email: String, password: String, passwordAgain:String)
object FormData {
val login = Form(
mapping(
"email" -> email,
"password" -> nonEmptyText
)(FormDataLogin.apply)(FormDataLogin.unapply)
)
val addMessage = Form(
mapping(
"content" -> nonEmptyText,
"tags" -> text
)(Message.formApply)(Message.formUnapply)
)
private[this] def accountForm(passwordMapping:Mapping[String]) = Form(
mapping(
"name" -> nonEmptyText,
"email" -> email,
"password" -> passwordMapping,
"passwordAgain" -> passwordMapping
)(FormDataAccount.apply)(FormDataAccount.unapply)
)
val updateAccount = accountForm(text)
val addAccount = accountForm(nonEmptyText)
}
开发者ID:digitalhudson,项目名称:dhdev,代码行数:39,代码来源:FormData.scala
示例4: passwordValidate
//设置package包名称以及导入依赖的类
package forms
import play.api.data.Forms._
import play.api.data.Mapping
import play.api.data.format.Formats._
import play.api.data.validation._
import play.api.i18n.MessagesApi
def passwordValidate(implicit messagesApi: MessagesApi): Mapping[String] = of[String] verifying passwordValidateCheck
private def passwordValidateCheck(implicit messagesApi: MessagesApi): Constraint[String] = Constraint[String]("password") {
case p if p == null => Invalid(ValidationError(messagesApi("error.required")))
case p if p.isEmpty => Invalid(ValidationError(messagesApi("error.required")))
case p if p.trim.isEmpty => Invalid(ValidationError(messagesApi("error.required")))
case p if p.length > 16 || p.length < 8 => Invalid(ValidationError(messagesApi("error.password.length")))
case p if passwordRegex.findFirstMatchIn(p).fold(true) { x => false } => Invalid(ValidationError(messagesApi("error.password.noval")))
case p => Valid
}
}
开发者ID:yukihirai0505,项目名称:sns-alert,代码行数:22,代码来源:CustomValidate.scala
示例5: ReadingForm
//设置package包名称以及导入依赖的类
package models.forms
import models.Reading
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormat
import play.api.data.Forms._
import play.api.data.format.Formats.doubleFormat
import play.api.data.{Form, Mapping}
import utils.DateUtils._
import utils.ValidationUtils._
object ReadingForm {
def dateStringMapping(datePattern: String, defaultDateProvider: DateProvider): Mapping[String] = {
optional(jodaLocalDate(datePattern)) transform(
old => old map (_.toString(datePattern)) getOrElse defaultDateProvider().toFormat(datePattern),
s => Some(LocalDate.parse(s, DateTimeFormat.forPattern(datePattern)))
)
}
def form(defaultDateProvider: DateProvider): Form[Reading] = Form(
mapping(
"reg" -> nonEmptyText(minLength = 2, maxLength = 8),
"date" -> dateStringMapping("yyyy/MM/dd", defaultDateProvider),
"mi" -> of[Double].verifying(inRange(0.0, 1000.00)),
"total" -> number(min = 0, max = 500000),
"litres" -> of[Double].verifying(inRange(0.0, 100.00)),
"cost" -> of[Double].verifying(inRange(0.0, 500.00))
)(Reading.apply)(Reading.unapply)
)
def apply(defaultDateProvider: DateProvider) = form(defaultDateProvider)
}
开发者ID:PeterPerhac,项目名称:fuel-meter,代码行数:36,代码来源:ReadingForm.scala
示例6: FormDataLogin
//设置package包名称以及导入依赖的类
package models
import dao.UserDao
import play.api.data.{Form, Mapping}
import play.api.data.Forms._
import play.api.data.validation.Constraints._
import play.api.data.validation.{Constraint, Invalid, Valid}
import scala.concurrent.Await
import scala.concurrent.duration.Duration
case class FormDataLogin(email: String, password: String)
case class FormDataAccount(name:String, email: String, password: String, passwordAgain:String)
object FormData {
val login = Form(
mapping(
"email" -> email,
"password" -> nonEmptyText
)(FormDataLogin.apply)(FormDataLogin.unapply)
)
val addMessage = Form(
mapping(
"content" -> nonEmptyText,
"tags" -> text
)(Message.formApply)(Message.formUnapply)
)
val uniqueEmail = Constraint[String] { email: String =>
val userFuture = UserDao.findByEmail(email)
Await.result(userFuture, Duration.Inf) match {
case Some(user) => Invalid("email already taken")
case None => Valid
}
}
private[this] def accountForm(passwordMapping:Mapping[String]) = Form(
mapping(
"name" -> nonEmptyText,
"email" -> email.verifying(maxLength(250), uniqueEmail),
"password" -> passwordMapping,
"passwordAgain" -> passwordMapping
)(FormDataAccount.apply)(FormDataAccount.unapply)
)
val updateAccount = accountForm(text)
val addAccount = accountForm(nonEmptyText)
}
开发者ID:asciiu,项目名称:polo,代码行数:54,代码来源:FormData.scala
注:本文中的play.api.data.Mapping类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论