播放2.4:窗体:找不到参数消息的隐式值:play.api.i18n.Messages [英] Play 2.4: Form: could not find implicit value for parameter messages: play.api.i18n.Messages

查看:200
本文介绍了播放2.4:窗体:找不到参数消息的隐式值:play.api.i18n.Messages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Play framework的新手,并试图模仿我本地机器中的 helloworld 示例,但遇到了一个错误:
$ b



路线: strong>

 #主页
GET / controllers.Application.index

#Hello action
GET / hello controllers.Application.sayHello


将静态资源从/ public文件夹映射到/ assets URL路径
GET / assets / *文件controllers.Assets.versioned(path =/ public,file:Asset)

控制器:

 包控制器

导入play.api.mvc._
import play.api.data._
import play.api.data.Forms._

import views._

class Application extends Controller {

val helloForm =表单(
元组($ b $) b名称 - > nonEmptyText,
重复 - >数字(最小= 1,最大= 100),
颜色 - >可选(文本)



def index =动作{
Ok(html.index(helloForm))
}

def sayHello = Action {implicit request =>
helloForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.index(formWithErrors)),
{case(name,repeat,color)=> Ok(html.hello( name,repeat.toInt,color))}

}
}

view:

  @(helloForm:Form [(String,Int, String])])

@import helper._

@main(title =helloworld'application){
< h1>配置您的'Hello world':< / h1>
@form(action = routes.Application.sayHello,args ='id - >helloform){
@inputText(
field = helloForm(name),
'args ='_label - >你叫什么名字?,'placeholder - >'World'


@inputText(
field = helloForm(repeat ),
args ='_label - >多少次?,'size - > 3,'placeholder - > 10

@select(
field = $ helloForm(color),
options = options(
- >Default,
red - >Red,
green - >绿色,
蓝色 - >蓝色
),
args ='_label - >选择一种颜色

< p class =buttons>
< input type =submitid =submit>
< p>




$ b我已经安装了Play 2.4并使用IntelliJ创建了项目通过 activator 模板实现的想法14

解决方案

在添加隐式消息

code>参数添加到视图中,您可以添加以下导入并使用旧的控制器类或甚至是对象,而无需进行任何其他更改:

  import play.api.Play.current 
import play.api.i18n.Messages.Implicits._


I am new to Play framework and tried to mimic the helloworld sample in my local machine but I encountered an error:

routes:

# Home page
GET        /                    controllers.Application.index

# Hello action
GET        /hello               controllers.Application.sayHello


# Map static resources from the /public folder to the /assets URL path
GET        /assets/*file        controllers.Assets.versioned(path="/public", file: Asset)

controller:

package controllers

import play.api.mvc._
import play.api.data._
import play.api.data.Forms._

import views._

class Application extends Controller {

  val helloForm = Form(
    tuple(
      "name" -> nonEmptyText,
      "repeat" -> number(min = 1, max = 100),
      "color" -> optional(text)
    )
  )

  def index = Action {
    Ok(html.index(helloForm))
  }

  def sayHello = Action { implicit request =>
      helloForm.bindFromRequest.fold(
      formWithErrors => BadRequest(html.index(formWithErrors)),
      {case (name, repeat, color) => Ok(html.hello(name, repeat.toInt, color))}
    )
  }
}

view:

@(helloForm: Form[(String,Int,Option[String])])

@import helper._

@main(title = "The 'helloworld' application") { 
    <h1>Configure your 'Hello world':</h1> 
    @form(action = routes.Application.sayHello, args = 'id -> "helloform") {
        @inputText(
            field = helloForm("name"),
            args = '_label -> "What's your name?", 'placeholder -> "World"
        )

        @inputText(
            field = helloForm("repeat"),
            args = '_label -> "How many times?", 'size -> 3, 'placeholder -> 10
        ) 
        @select(
            field = helloForm("color"),
            options = options(
                "" -> "Default",
                "red" -> "Red",
                "green" -> "Green",
                "blue" -> "Blue"
            ),
            args = '_label -> "Choose a color"
        ) 
        <p class="buttons">
            <input type="submit" id="submit">
        <p> 
    } 
}

I have Play 2.4 installed and created the project using IntelliJ Idea 14 via activator template.

解决方案

After adding implicit messages parameters to views you can just add the following imports and use the old controller classes or even objects without any additional changes:

import play.api.Play.current
import play.api.i18n.Messages.Implicits._

这篇关于播放2.4:窗体:找不到参数消息的隐式值:play.api.i18n.Messages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆