0
我正在使用Scalate和Jade的Scalatra。當過我嘗試應用模板取值值不被應用到模板,我得到一個NoValueSetException ...這裏是我的代碼有:Scalate Scalatra NoValueSetException with jade
// --------- In PostsServlet ------------------
get("/:page") {
/*
val page:Int = params.getOrElse("page", "1").toInt
val posts = PostCollection.page(page)
*/
contentType="text/html"
jade("/index.jade", "foo" -> "bar")
}
// ------------------ In index.jade ----------------------
[email protected] var foo : String
-attributes("title") = "Circuits Of Imagination"
-attributes("headline") = "Writings"
和異常:
The value for 'foo' was not set
org.fusesource.scalate.NoValueSetException: The value for 'foo' was not set
at org.fusesource.scalate.RenderContext$$anonfun$attribute$1.apply(RenderContext.scala:159)
at org.fusesource.scalate.RenderContext$$anonfun$attribute$1.apply(RenderContext.scala:159)
at org.fusesource.scalate.RenderContext$class.attributeOrElse(RenderContext.scala:167)
您的代碼看起來沒問題。它適用於我,當我嘗試它。你有一個測試項目嗎?你也可以這樣做:'val page = params.getAs [Int](「page」)。getOrElse(1)' –
很遺憾,大家都說它看起來很好。我沒有代碼了,因爲我切換到使用Fink(基於Scalatra的CMS)。 – tantalum