2

私の Clojure アプリケーションでは、Web フレームワークとして Noir を使用しています。一部のデータをmongodbデータベースに保存する投稿ページを1つ定義してから、別のページをレンダリングしようとしています:

(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)
4

2 に答える 2

2

まったく同じ URL を指定する必要があります。

 (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)
于 2012-09-21T21:19:17.447 に答える
1

(render "/delivery/list/" id)コードとして試してください。

于 2012-09-21T09:04:55.197 に答える