Announcement Announcement Module
Collapse
No announcement yet.
Why is ModelAttribute annotation not working? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why is ModelAttribute annotation not working?

    Hi,

    I'm using Spring 3.0.2. When I visit "/sweeps/rules/form", I want to be able to enter in a new object, so I have this in my controller ...

    Code:
        /**
         * For every request for this controller, this will 
         * create a UserPromotionRule instance for the form.
         */
        @ModelAttribute
        public UserPromotionRule newRequest(@RequestParam(required=false) Integer id) {
            return (id != null ? userPromotionRuleDao.findUserPromotionRuleById(id) : new UserPromotionRule());
        }
    
        /**
         * <p>UserPromotionRule form request.</p>
         * 
         * <p>Expected HTTP GET and request '/sweeps/rules/form'.</p>
         */
        @RequestMapping(value="/sweeps/rules/form", method=RequestMethod.GET)
        public void form() {
        	log.debug("here we are!");
        }
    but I'm getting the error, "java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.Integer], and no parameter name information found in class file either", when I visit the page that's supposed to create the form object. I have specified "required=false" in my ModelAttribute annotation. Why is spring saying I need the Integer attribute?

    Thanks, - Dave


    Complete stack trace is ...

    Code:
    2010-04-20 15:07:40,417 [TP-Processor8] DEBUG org.springframework.web.servlet.DispatcherServlet  - Could not complete requestorg.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public void com.lvcva.web
    .controller.promotions.UserPromotionRuleController.form()]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.Integer], and no parameter name information found in class file either.        at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)        at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
            at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
            at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
            at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
            at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
            at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
            at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
            at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
            at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

  • #2
    Try changing:

    @RequestParam(required=false)

    to be:

    @RequestParam(value="id", required=false)

    Comment


    • #3
      That worked!!!

      Thanks so much, - Dave

      Comment

      Working...
      X