Play Framework 2.0-views.render引发异常 [英] Play Framework 2.0 - views.render throws exception

查看:118
本文介绍了Play Framework 2.0-views.render引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我收到以下错误:

render(java.lang.String) in views.html.index cannot be applied to (play.data.Form<controllers.Application.Hello>)

指向以下代码块:

  /**
   * Home page
  */
  public static Result index() {
     return ok(index.render(form(Hello.class)));
  }

Eclipse也无法解析索引对象上的.render方法.

Also Eclipse cannot resolve the .render method on the index object.

the method render(String) in the type index is not applicable for the arguments (Form<Application.Hello>)

我定义了以下导入:

package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import play.data.validation.Constraints.*;

import java.util.*;
import views.html.*;

hello.scala.html和index.scala.html也可在文件夹app/views/

Also the hello.scala.html and the index.scala.html are available in the folder app/views/

知道我做错了什么吗?

推荐答案

Play 2.0中的每个视图都是Scala函数,其中包含参数,很可能您在index.sacala.html开头声明的字符串中有

Each view in Play 2.0 is Scala function which contains arguments, most probably you have in the index.sacala.html String declared at the beginning:

@(message: String)

,它应该是您的表格:

在控制器中:

final static Form<MyModel> myForm = form(MyModel.class);

public static Result blank() {
    return ok(formNew.render(myForm));
}

并在视图中:

@(myForm: Form[MyModel])  

这篇关于Play Framework 2.0-views.render引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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