Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to prevent @ModelAttribute to instantiate a calendar in a method
    primarykey
    data
    text
    <p>I have a method in a controller:</p> <pre><code>public FormValidationResult submitFormAndSendEmail(@Valid ContactForm form, BindingResult result, @HttpSessionParam(value = "lastTimeContactFormSent", required = false) Calendar lastTimeContactFormSent) </code></pre> <p>As you can see I have created a @HttpSessionParam annotation, this will take a variable from the HttpSession and put it into the specified method parameter.</p> <p>However...</p> <p>Before the argument is being resolved, I recieve an InstantiationExceptionConstructorAccessorImpl because calendar cannot be instantiated by a default constructor.</p> <p>Using the given stacktrace, I see that the HandlerMethodInvoker within "resolveModelAttribute" is causing the instantiation. </p> <p>How can i prevent this? I don't want an instantiation, I want to use my own WebArgumentResolver in order to fill the method parameter.</p> <p>Any clues?</p> <p>More info: Stacktrace by Spring (3.0.4):</p> <pre><code> java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:772) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:356) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415) </code></pre> <p>I don't see the debugger hit the webargumentresolver.</p> <p>The argument is defined in my application context (xml) as following:</p> <pre><code> &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="customArgumentResolver" ref="sessionParamResolver"/&gt; &lt;/bean&gt; &lt;!-- annotation to resolve httpSession attributes --&gt; &lt;bean id="sessionParamResolver" class="nl.usgpeople.vakgilde.spring.mvc.extensions.SessionParamArgumentResolver"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload