当前位置: 首页>>代码示例>>Scala>>正文


Scala longNumber类代码示例

本文整理汇总了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))
  }
} 
开发者ID:makeajourney,项目名称:play-products-example,代码行数:56,代码来源:Products.scala

示例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)
			}
		)
	}
} 
开发者ID:beniaminp,项目名称:PlayTutorial,代码行数:58,代码来源:Products.scala

示例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)
  )
} 
开发者ID:agoetschm,项目名称:linkmanager,代码行数:28,代码来源:NewLinkForm.scala

示例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)
      }
    )
  }
} 
开发者ID:yomajkel,项目名称:scala_play_book,代码行数:61,代码来源:ProductsController.scala

示例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))
  }
} 
开发者ID:Sup3rdom,项目名称:grp1A-pizza,代码行数:23,代码来源:ItemController.scala


注:本文中的play.api.data.Forms.longNumber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。