2012-09-21 26 views
2

在我的Clojure应用程序中,我使用Noir作为Web框架。 我有一个帖子页面中的定义一些数据保存到MongoDB数据库,然后我试图呈现另一页:Noir呈现函数导致NullPointerException

(defpage "/delivery/save" [delivery] 
(let [id (save-delivery delivery)] 
    (render "/delivery/list" id)) 

我再有其它页:

(defpage "/delivery/list/:id" {:id id} 
    (this should render the page)) 

不过我当调用渲染函数时会出现NullPointerException。 任何想法为什么会发生这种情况? 如果您需要更多详细信息,请告诉我。

感谢, 尼科

这里的堆栈跟踪:

java.lang.NullPointerException 
    at noir.core$render.doInvoke(core.clj:161) 
    at clojure.lang.RestFn.invoke(RestFn.java:423) 
    at mailjure.views.delivery$POST__delivery__save.invoke(delivery.clj:115) 
    at mailjure.views.delivery$eval477$fn__478.invoke(delivery.clj:109) 
    at compojure.core$if_route$fn__271.invoke(core.clj:39) 
    at compojure.core$if_method$fn__264.invoke(core.clj:24) 
    at compojure.core$routing$fn__286.invoke(core.clj:98) 
    at clojure.core$some.invoke(core.clj:2390) 
    at compojure.core$routing.doInvoke(core.clj:98) 
    at clojure.lang.RestFn.applyTo(RestFn.java:139) 
    at clojure.core$apply.invoke(core.clj:603) 
    at compojure.core$routes$fn__290.invoke(core.clj:103) 
    at noir.server.handler$init_routes$fn__1422.invoke(handler.clj:92) 
    at noir.request$wrap_request_map$fn__1324.invoke(request.clj:14) 
    at hiccup.middleware$wrap_base_url$fn__860.invoke(middleware.clj:12) 
    at noir.session$noir_flash$fn__1347.invoke(session.clj:92) 
    at ring.middleware.flash$wrap_flash$fn__642.invoke(flash.clj:14) 
    at noir.session$noir_session$fn__1337.invoke(session.clj:56) 
    at ring.middleware.session$wrap_session$fn__635.invoke(session.clj:40) 
    at ring.middleware.cookies$wrap_cookies$fn__572.invoke(cookies.clj:150) 
    at noir.cookies$noir_cookies$fn__1188.invoke(cookies.clj:66) 
    at ring.middleware.cookies$wrap_cookies$fn__572.invoke(cookies.clj:150) 
    at noir.validation$wrap_noir_validation$fn__1375.invoke(validation.clj:90) 
    at noir.statuses$wrap_status_pages$fn__1286.invoke(statuses.clj:34) 
    at ring.middleware.reload$wrap_reload$fn__712.invoke(reload.clj:18) 
    at noir.exception$wrap_exceptions$fn__1317.invoke(exception.clj:57) 
    at noir.options$wrap_options$fn__1277.invoke(options.clj:34) 
    at compojure.core$routing$fn__286.invoke(core.clj:98) 
    at clojure.core$some.invoke(core.clj:2390) 
    at compojure.core$routing.doInvoke(core.clj:98) 
    at clojure.lang.RestFn.applyTo(RestFn.java:139) 
    at clojure.core$apply.invoke(core.clj:603) 
    at compojure.core$routes$fn__290.invoke(core.clj:103) 
    at ring.middleware.keyword_params$wrap_keyword_params$fn__445.invoke(keyword_params.clj:27) 
    at ring.middleware.nested_params$wrap_nested_params$fn__482.invoke(nested_params.clj:65) 
    at ring.middleware.params$wrap_params$fn__390.invoke(params.clj:76) 
    at ring.middleware.multipart_params$wrap_multipart_params$fn__417.invoke(multipart_params.clj:103) 
    at ring.adapter.jetty$proxy_handler$fn__377.invoke(jetty.clj:16) 
    at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle(Unknown Source) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 
+0

堆栈跟踪...? – Ankur

回答

2

你需要指定完全相同的网址:

(defpage "/delivery/list/:id" {id :id} 
    "whoot!") 

(defpage "/delivery/save" [] 
    (let [id 100] 
    (render "/delivery/list/:id" id))) 

但是这是丑陋的,这是更好地给的名字到您的网页:

(defpage delivery-page "/delivery/list/:id" {id :id} 
    "whoot!") 

(defpage "/delivery/save" [] 
    (let [id 100] 
    (render delivery-page id))) 

这是非常整洁。另外它的优点是您可以轻松测试您的交付页面:

(delivery-page 123) 
+0

你是一个高手!谢谢..它的工作原理!:) –

+0

哇,我不知道你可以命名页面。奖励! –

1

尝试(render "/delivery/list/" id)为你的代码。

+0

完成..但没有运气很遗憾:( –

+0

我也试过了(渲染“/ delivery/list”{:id id}) –

相关问题