本文整理汇总了Scala中play.api.data.Forms.longNumber类的典型用法代码示例。如果您正苦于以下问题:Scala longNumber类的具体用法?Scala longNumber怎么用?Scala longNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了longNumber类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Products
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc._
import javax.inject.Inject
import play.api.i18n.{Messages, MessagesApi, I18nSupport}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import models.Product
class Products @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
def list = Action { implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action {
implicit request => Product.findByEan(ean).map {
// rendering product details
product => Ok(views.html.products.details(product))
}.getOrElse(NotFound) // return page 404
}
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying("validation.ean.duplicate", Product.findByEan(_).isEmpty), // form? field? ????
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply) // form? model ?? mapping
)
def save = Action {
implicit request => val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = {
form => Redirect(routes.Products.newProduct()).
flashing(Flash(form.data) + ("error" -> Messages("validation.errors")))
},
success = {
newProduct => Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.Products.show(newProduct.ean)).flashing("success" -> message)
}
)
}
def newProduct = Action {
implicit request => val form = if (request2flash.get("error").isDefined)
productForm.bind(request2flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
}
示例2: Products
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.i18n.{Messages, I18nSupport, MessagesApi}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import models.Product
class Products @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport{
def list = Action{ implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action{ implicit request =>
Product.findByEan(ean).map{ product =>
Ok(views.html.products.details(product))
}.getOrElse(NotFound)
}
def newProduct = Action{ implicit request =>
val form = if(request.flash.get("error").isDefined)
productForm.bind(request.flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying(
"validation.ean.duplicate", Product.findByEan(_).isEmpty),
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply)
)
def save = Action { implicit request =>
val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = {form =>
Redirect(routes.Products.newProduct()).flashing(Flash(form.data) +
("error" -> Messages("validation.errors")))
},
success = {newProduct =>
Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.Products.show(newProduct.ean)).flashing("success" -> message)
}
)
}
}
示例3: NewLinkForm
//设置package包名称以及导入依赖的类
package models.forms
import models.LinkAddData
import play.api.data.Form
import play.api.data.Forms.{mapping, nonEmptyText, optional, text, longNumber}
import play.api.data.validation.{Constraint, Invalid, Valid}
object NewLinkForm {
private val urlRegex = "(^|[\\s.:;?\\-\\]<\\(])(https?://[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,?]+[\\w/#](\\(\\))?)(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])"
private val urlContraint = Constraint[String] { s: String =>
if (s.matches(urlRegex))
Valid
else
Invalid("is not a valid url")
}
val form = Form(
mapping(
"url" -> nonEmptyText.verifying(urlContraint),
"name" -> optional(text),
"description" -> optional(text),
"parentId" -> optional(longNumber)
)(LinkAddData.apply)(LinkAddData.unapply)
)
}
示例4: ProductsController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api.mvc._
import models.Product
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import play.api.i18n.Messages
@Singleton
class ProductsController @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying("validation.ean.duplicate", Product.findByEan(_).isEmpty),
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply)
)
def list = Action { implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action { implicit request =>
Product.findByEan(ean).map { product =>
Ok(views.html.products.details(product))
}.getOrElse(NotFound)
}
def newProduct = Action { implicit request =>
val form = if (request.flash.get("error").isDefined)
productForm.bind(request.flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
def save = Action { implicit request =>
val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = { form =>
Redirect(routes.ProductsController.newProduct).
flashing(Flash(form.data) + ("error" -> Messages("validation.errors")))
},
success = { newProduct =>
Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.ProductsController.show(newProduct.ean)).
flashing("success" -> message)
}
)
}
}
示例5: ItemController
//设置package包名称以及导入依赖的类
package controllers
import controllers.Auth.Secured
import forms.CreateOrderForm
import play.api.data.Form
import play.api.data.Forms.{list, longNumber, mapping, number}
import play.api.mvc.Controller
object ItemController extends Controller with Secured {
val orderForm = Form(
mapping(
"itemID" -> longNumber,
"quantity" -> number,
"size" -> number,
"extraID" -> list(longNumber)
)(CreateOrderForm.apply)(CreateOrderForm.unapply))
def showItems(categoryID: Long) = withUser_Customer { user => implicit request =>
Ok(views.html.welcomeUser(controllers.ItemController.orderForm, user, categoryID))
}
}