• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala nonEmptyText类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中play.api.data.Forms.nonEmptyText的典型用法代码示例。如果您正苦于以下问题:Scala nonEmptyText类的具体用法?Scala nonEmptyText怎么用?Scala nonEmptyText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了nonEmptyText类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ContactController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject._

import models.{ContactDB, MongoConnector}
import play.api._
import play.api.i18n.Messages
import play.api.mvc._
import play.api.mvc.{Action, Controller, Flash, Request}
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.Forms.{mapping, nonEmptyText}


import play.api.data.Forms.{longNumber, mapping, nonEmptyText}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global



@Singleton
class ContactController  @Inject() extends Controller{

  val contactForm = Form(tuple(
    "Name" -> text,
      "Email" -> text,
      "Message" -> text
    ))

  def saveContact = Action {
    implicit request =>
      val newContactForm = contactForm.bindFromRequest()
      newContactForm.fold(success = {
        newContact =>
          //Create a contact object using form data
          val newContactID = ContactDB.findNextID()
          print(newContactID)
          println(newContact._2)
          val newContactRequest = new ContactDB(newContactID, newContact._1, newContact._2, newContact._3)

          //Insert into contact collection
          MongoConnector.collectionContact.insert(newContactRequest)
          Ok(views.html.home())
      }, hasErrors = {
        form =>
          Redirect(routes.ContactController.contact()).flashing(Flash(form.data) + ("error" -> Messages("contact.validation.errors")))
      })
      }

  def contact = Action {
    implicit request =>
      val form = if (request2flash.get("error").isDefined)
        contactForm.bind(request2flash.data)
      else
        contactForm
      Ok(views.html.contact(form))
  }


} 
开发者ID:nkaraolis,项目名称:NBGardensNewPlay,代码行数:62,代码来源:ContactController.scala


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例6: CatalogueController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject._

import models.{CatalogueDB, MongoConnector}
import play.api._
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.Messages
import play.api.mvc._
import play.api.mvc.{Action, Controller, Flash, Request}
import play.api.data.Forms.{longNumber, mapping, nonEmptyText}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global


@Singleton
class CatalogueController @Inject() extends Controller{

  val catalogueForm = Form(tuple(
      "Name" -> nonEmptyText,
      "Email" -> nonEmptyText,
      "Address Line 1" -> nonEmptyText,
      "Address Line 2" -> nonEmptyText,
      "Town/City" -> nonEmptyText,
      "Postcode" -> nonEmptyText
    ))

  def saveCatalogue = Action {
    implicit request =>
      val newCatalogueForm = catalogueForm.bindFromRequest()
      newCatalogueForm.fold(success = {
        newCatalogue =>
          //Create a contact object using form data
          val newCatalogueID = CatalogueDB.findNextID()
          print(newCatalogueID)
          println(newCatalogue._2)
          val newCatalogueRequest = new CatalogueDB(newCatalogueID, newCatalogue._1, newCatalogue._2, newCatalogue._3, newCatalogue._4, newCatalogue._5, newCatalogue._6)

          //Insert into contact collection
          MongoConnector.collectionCatalogue.insert(newCatalogueRequest)
          Ok(views.html.home())
      }, hasErrors = {
        form =>
          Redirect(routes.CatalogueController.catalogue()).flashing(Flash(form.data) + ("error" -> Messages("catalogue.validation.errors")))
      })
  }

  def catalogue = Action {
    implicit request =>
      val form = if (request2flash.get("error").isDefined)
        catalogueForm.bind(request2flash.data)
      else
        catalogueForm
      Ok(views.html.catalogue(form))
  }


} 
开发者ID:nkaraolis,项目名称:NBGardensNewPlay,代码行数:61,代码来源:CatalogueController.scala


示例7: EmployeeController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import play.api.mvc.{Action, Controller}
import models.Employee
import play.api.data.Form
import play.api.data.Forms.{mapping, nonEmptyText}
import play.api.libs.json.Json
import play.api.libs.ws._
import scala.concurrent.ExecutionContext.Implicits.global

import scala.concurrent.Future

/**
  * Created by Orange on 20/06/2016.
  */
class EmployeeController @Inject() (ws:WSClient) extends Controller{

 private val employeeForm: Form[Employee] = Form (
     mapping (
       "empName" -> nonEmptyText,
       "email" -> nonEmptyText
     ) (Employee.apply)(Employee.unapply)
  )

  def save = Action { implicit request =>
    val newEmployee = employeeForm.bindFromRequest.get
    val futureResponse: Future[WSResponse] = ws.url("http://localhost:9000/addEmployee").post(Json.toJson(newEmployee))
    Redirect(routes.EmployeeController.list())
  }

  def list = Action.async{
    ws.url(s"http://localhost:9000/getAllEmployees").get() map {
      response => Ok(response.body)
    }
  }

    def newEmployee = Action { implicit request =>
      Ok(views.html.employee.editEmployee(employeeForm, Employee.findAll))
    }



} 
开发者ID:MaithiliLabhe,项目名称:EmployeeDetailsApp,代码行数:46,代码来源:EmployeeController.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Request类代码示例发布时间:2022-05-23
下一篇:
Scala Button类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap