首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Noir render函数导致NullPointerException

Noir render函数导致NullPointerException
EN

Stack Overflow用户
提问于 2012-09-21 16:36:29
回答 2查看 290关注 0票数 2

在我的Clojure应用程序中,我使用Noir作为web框架。我定义了一个post页面,它将一些数据保存到mongodb数据库中,然后我尝试呈现另一个页面:

代码语言:javascript
复制
(defpage "/delivery/save" [delivery]
 (let [id (save-delivery delivery)]
    (render "/delivery/list" id))

然后我又有了另一个页面:

代码语言:javascript
复制
(defpage "/delivery/list/:id" {:id id}
   (this should render the page))

然而,当我调用render函数时,我得到了一个NullPointerException。你知道为什么会发生这种事吗?如果你需要更多的细节,请告诉我。

谢谢,Nico

下面是堆栈跟踪:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-22 05:19:17

您需要指定完全相同的url:

代码语言:javascript
复制
 (defpage "/delivery/list/:id" {id :id}
   "whoot!")

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

但是这很难看,最好给你的页面命名:

代码语言:javascript
复制
 (defpage delivery-page "/delivery/list/:id" {id :id}
   "whoot!")

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

这是相当整洁的。它还有一个优点,那就是你可以很容易地测试你的交付页面:

代码语言:javascript
复制
 (delivery-page 123)
票数 2
EN

Stack Overflow用户

发布于 2012-09-21 17:04:55

尝试使用(render "/delivery/list/" id)作为您的代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12526985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档