2014-07-19 97 views
1

我是新的遊戲框架,我試圖開發示例Java應用程序日食顯示上渲染)錯誤(play2

我已經創造了新的HTML頁面的test.html

在控制器是工作如果我們簡單地以字符串的形式返回結果,即返回ok(「hello world」),但它只是格式化所有樣式/文本,並在用戶界面上顯示「hello world」。

public static Result test() { 
     return ok("hello world"); 
     } 

//做工精細

但是當我嘗試這個

public static Result test(){ 
     return ok(test.render()); 
     } 

//給錯誤

它提供了以下錯誤

它給錯誤

[錯誤]/opt/ahsen/play-2.2.3/testapp/app/controllers/Application.java:15:render(java.lang.String,play.api.temp lates.Html)在views.html.test中無法應用()

[error] return ok(test.render());

[錯誤](編譯:編譯)javac的返回非零的退出代碼

這裏是我的test.html文件

@(title: String)(content: Html) 

    <!DOCTYPE html> 

    <html> 
    <head> 
    <title>@title</title> 
    <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> 
    <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> 
    <script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"> 
    </script> 
    </head> 
    <body> 
     @content 
    </body> 
</html> 

幫助,請

回答

2

你的test.html模板需要兩個參數

@(title: String)(content: Html) 

所以你需要將它們傳遞給控制中的模板呃

public static Result test(){ 
    String title = "test title"; 
    Html content = // create content 
    return ok(test.render(title, content)); 
} 

更好的解決方案

的test.html看起來而不是作爲一個更廣泛的佈局模板。我會創建一個單獨的文件來生成內容,而不是直接從控制器傳遞它。

content.html

@(title: String) 

@test(title){ 
    <span>this is the content</span> 
} 

和Controller它是這樣的。

public static Result test(){ 
    String title = "test title"; 
    return ok(content.render(title)); 
}