我正在尝试从doc运行hello world应用程序。
我收到以下错误:
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方法。
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.*;
此外,文件夹app / views /
中提供了hello.scala.html和index.scala.html知道我做错了吗?
答案 0 :(得分:9)
Play 2.0中的每个视图都是包含参数的Scala函数,最有可能是在index.sacala.html开头声明的字符串中:
@(message: String)
它应该是你的形式:
控制器中的:
final static Form<MyModel> myForm = form(MyModel.class);
public static Result blank() {
return ok(formNew.render(myForm));
}
并在视图中:
@(myForm: Form[MyModel])