2013-08-21 69 views
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) 
+0

您的代碼看起來沒問題。它適用於我,當我嘗試它。你有一個測試項目嗎?你也可以這樣做:'val page = params.getAs [Int](「page」)。getOrElse(1)' –

+0

很遺憾,大家都說它看起來很好。我沒有代碼了,因爲我切換到使用Fink(基於Scalatra的CMS)。 – tantalum

回答

0

嘗試通過以下命令

sbt clean clean-files 

清洗溫度/生成的文件然後啓動碼頭服務器。它可能有幫助。