2012-08-23 61 views
1

我在使用scala編寫可重用代碼時遇到了問題。Java Play 2 - 在scala中作爲參數的函數

如果我有像

@helper.form(action = routes.Guides.addComment(category,title)) { 

有沒有辦法用一個變量來代替它?

僞代碼

@(func : Function) 
@helper.form(action = func) { 

編輯:

哦....現在是有點明顯。函數本身應該返回一個字符串,所以我想我可以這樣說這樣的事情

@(func :String) 
.. 

return ok (form.render(routes.Guides.test())) 

測試現在

回答

2

我可以建議一個替代?直接使用Call。在Scala中,你甚至可以只傳遞一部分路由,並從控制器中填充其餘部分(當你使用分頁時非常有用)。

+0

你可以解釋一下如何使用這個分頁? –

+0

您能否在單獨的問題中提出這個問題? –

2

想通了。

routes.Guides.test().url 

你的URL,然後你可以使用它作爲一個參數

例如

@guidesComment((routes.Guides.addComment(ug.category,ug.title)).url) 

guidesComment看起來像這樣

@(func: String) 

然後使用它是這樣的

<form action="@func" method="POST">