【发布时间】:2013-08-21 16:06:57
【问题描述】:
我将 Scalatra 与 Scalate 和 Jade 一起使用。当我尝试应用一个接受值的模板时,这些值并没有被应用到模板上,我得到一个 NoValueSetException ......这是我拥有的代码:
// --------- 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 ----------------------
-@ 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)。