Announcement Announcement Module
Collapse
No announcement yet.
Problem with a simple command controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with a simple command controller

    Im new to spring so if im going at this the wrong way, please say so!

    I have a simple AbstractCommandController, with a command object NewsListCommand, that takes an Integer page with setPage, getPage.

    Now ive spent some time to get this thing to compile and wire properly, and then i stumble on this error.

    The controller is mapped to /index via <bean name="/index" ...>, it works fine if I call it via /index?page=1. But if the page parameter is missing, the whole thing crashes...

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    
    root cause
    
    java.lang.NullPointerException
    	my.test.app.MainController.handle(Unknown Source)
    	org.springframework.web.servlet.mvc.AbstractCommandController.handleRequestInternal(AbstractCommandController.java:84)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    So am i going at this the wrong way? Is there a way to tell spring that the parameter might not be there (theres always that possiblity, why is it crashing anyhow?).

    Is there a simpler way of doing this possibly? I just need to get a (possible) param from the request, preferrably using spring to do it, if i wanted to use plain servlets, i'd do so

    Any input appreciated.

  • #2
    Setting the encapsulated Integer to:
    Code:
    Integer page = new Integer(0);
    resolved the issue, weird it wasn't mentioned in 'Spring in action'.

    Comment

    Working...
    X