开发者

clojure/compojure/hiccup NullPointerException

The stack trace I have does not contain any reference to my code. I'm not sure how to begin finding out what might be wrong here:

LazySeq.java:47 clojure.lang.LazySeq.sval
LazySeq.java:56 clojure.lang.LazySeq.seq
Cons.java:39    clojure.lang.Cons.next
RT.java:560 clojure.lang.RT.next
core.clj:61 clojure.core/next
core.clj:461    clojure.core/str$fn[fn]
core.clj:463    clojure.core/str
RestFn.java:140 clojure.lang.RestFn.applyTo
core.clj:540    clojure.core/apply
core.clj:90 hiccup.core/eval460$fn[fn]
MultiFn.java:163    clojure.lang.MultiFn.invoke
Var.java:365    clojure.lang.Var.invoke
stacktrace.clj:26   ring.middleware.stacktrace/html-ex-view
stacktrace.clj:40   ring.middleware.stacktrace/html-ex-response
stacktrace.clj:51   ring.middleware.stacktrace/ex-response
stacktrace.clj:61   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
reload_modified.clj:15  ring.middleware.reload-modified/wrap-reload-modified$fn[fn]
stacktrace.clj:59   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
jetty.clj:17    ring.adapter.jetty/proxy-handler$fn[fn]
(Unknown Source)        ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle
HandlerWrapper.java:152 org.mortbay.jetty.handler.HandlerWrapper.handle
Server.java:324 org.mortbay.jetty.Server.handle
HttpConnection.java:534 org.mortbay.jetty.HttpConnection.handleRequest
HttpConnection.java:879 org.mortbay.jetty.HttpConnection$RequestHandler.content
HttpParser.java:741 org.mortbay.jetty.HttpParser.parseNext
HttpParser.java:213 org.mortbay.jetty.HttpParser.parseAvailable
HttpConnection.java:403 org.mortbay.jetty.HttpConnection.handle
SocketConnector.java:228    org.mortbay.jetty.bio.SocketConnector$Connection.run
QueuedThreadPool.java:522   org.mortbay.thread.QueuedThreadPool$PoolThread.run

This happens after a form submit--the controller writes a record to the db and redirects to the page:

(defn create-submit [& m]
  (let [p (model/create m)]
      (response/redirect (str "/post/" (:id p开发者_如何学JAVA)))))

I see hiccup in the stack trace but there is no page rendering going on here. And the browser still points to the original page, not the redirected page, so I'm thinking that the redirect never happens.

Ideas?

EDIT:

With some println's I've tracked it down to the model/create call, which is calling clojureql to conj! the new record. The first println shows up in the console window and the second doesn't.

(defn create [m] 
    (let [p (new-post-from m)] 
        (println "about to add p to table " (:id p)) 
        (cql/conj! (cql/table :posts) p)
        (println "after adding p to table")
    p)) 


Well the reason was that my route definition looked something like this:

(POST "/post/create/submit" (params :params) (post/create-submit))

Where I was needing to passing params to the create-submit call. Because the definition of create-submit parameters was [& m] I guess it didn't complain about wrong number of parameters.

CORRECTION: And also the model/create method was throwing because I had not added a require for the db.clj file, which is where I had my cql/open-global call.

The stack trace was completely non-obvious--I would expect it to point to some place under cql/conj! where it's trying to establish a connection. Instead it was pointing to hiccup which makes no sense at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜