View Full Version : MultiActionController - problem with methodNameResolver
lukasz
Jul 27th, 2005, 06:03 AM
Hi!
I have controller extending MultiActionController with serveral methods (including handleRequestInternal()). I want to call each method using "action" parameter and call handleRequestInternal() when parameter is not present, but the handleRequestInternal() is called allways. When I delete handleRequestInternal() method it works fine but when "action" parameter is not present i get 404 error... Any suggestions?
robh
Jul 28th, 2005, 03:08 PM
Can you post your code?
Rob
lukasz
Jul 29th, 2005, 12:42 PM
Here it is:
<bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.Pa rameterMethodNameResolver">
<property name="paramName"><value>action</value></property>
</bean>
<bean id="drawController" class="my.package.DrawController">
<property name="drawManager" ref="drawManager" />
<property name="methodNameResolver" ref="methodNameResolver" />
<property name="defaultView"><value>admin/draw</value></property>
</bean>
<prop key="/admin/draw*.html">drawController</prop>
in DrawController i have methods:
public ModelAndView drawForm(HttpServletRequest request, HttpServletResponse response);
public ModelAndView draw(HttpServletRequest request, HttpServletResponse response) throws Exception;
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception;
if (handleRequestInternal() is present then) {
/admin/draws.html?action=drawForm - doesn't work
} else {
/admin/draws.html - doesn't work
}
What could be wrong?
robh
Jul 29th, 2005, 01:10 PM
I think I see the problem here - are you overriding the handleRequestInternal method but not calling super.handleRequestInternal()? In general, you shouldn't override this method but if you do you must remember to invoke the method on the super class.
Rob
lukasz
Jul 29th, 2005, 09:01 PM
Now, method looks like this:
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("handleRequestInternal()");
super.handleRequestInternal(request, response);
return new ModelAndView(getDefaultView());
}
but it doesn't seem to work:
for /admin/draw.html I get:
DEBUG my.packageDrawController (32) - handleRequestInternal()
WARN org.springframework.web.servlet.PageNotFound (308) - No handling method can be found for request [org.apache.coyote.tomcat5.CoyoteRequestFacade@ad48 3]
for /admin/draw.html?action=drawForm :
DEBUG my.package.DrawController (32) - handleRequestInternal()
DEBUG my.package.DrawController (37) - registerForm()
I must do something wrong...
robh
Jul 31st, 2005, 06:25 PM
You can't override how this method works, you can only add additional behavior to it. You have to return the ModelAndView returned by handleRequestInternal().
Rob
lukasz
Aug 3rd, 2005, 07:55 AM
Maybe You could give me an example?
I tried with:
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("handleRequestInternal()");
return super.handleRequestInternal(request, response);
}
but I get:
DEBUG my.package.DrawController (32) - handleRequestInternal()
WARN org.springframework.web.servlet.PageNotFound (308) - No handling method can be found for request [org.apache.coyote.tomcat5.CoyoteRequestFacade@1948 0b8]
DEBUG org.springframework.web.servlet.DispatcherServlet (709) - Null ModelAndView returned to DispatcherServlet with name 'MyServlet': assuming HandlerAdapter completed request handling
and with: public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("handleRequestInternal()");
ModelAndView mav = super.handleRequestInternal(request, response);
mav.setViewName(getDefaultView());
return mav;
}
I get:
DEBUG my.package.DrawController (32) - handleRequestInternal()
WARN org.springframework.web.servlet.PageNotFound (308) - No handling method can be found for request [org.apache.coyote.tomcat5.CoyoteRequestFacade@8ef1 77]
Thanks in advance!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.