2012-04-05 58 views
3

我試圖從doc運行hello world app。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方法。

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所在的文件夾的應用程序/視圖/可

任何想法我做錯了?

回答

9

在播放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]) 
+0

感謝您的幫助。明白了,它現在起作用了! – 2012-04-05 15:57:54