-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After a successfull validation Spring does not call the onSubmit method with signature of (request, response,object, bindexception) [SPR-692] #5420
Comments
Juergen Hoeller commented Sorry, I can't reproduce this. Have a look at SimpleFormController's implementation (which is pretty easy to read): processFormSubmission delegates to the onSubmit version with all arguments, which in turn cascades down to the simpler onSubmit versions. I can't see an execution path where the simpler onSubmit methods get called directly... Please analyze your scenario thoroughly, and consider using a debugger to trace the execution path. You might want to place a breakpoint in SimpleFormController's processFormSubmission and see where you go from there. Juergen |
Juergen Hoeller commented Closed for the time being. To be reopened if the issue is reproducible in specific scenarios. Juergen |
Venkatt Guhesan commented I had a few people email me with the same issue and here's what I have discovered: #1: #2: #3: So if you override say #1 and #3 in a class, it seems that #3 gets called on validation errors and #1 will get called when there are no validation errors (provided you have a Validator defined for this controller). I've noticed that if I override: Here is an example that might help explain this:
} I hope this helps understand the issue and how to get around it... If anyone have any questions, feel free to contact me @ veni_veni### Venkatt |
Mark Aden commented This is indeed a bug. It just so happens that I have implemented a class called LoginController that extends SimpleFormController and I am having the same exact problem. The onSubmit method with signature "onSubmit (request, response, command, errors)" is being bypassed. My submited form has no validation errors and yet spring keeps calling the method with signature "onSubmit(command)" even though "onSubmit (request, response, command, errors)" is overwritten. The weird thing is this doesn't happen with any of my other SimpleFormControllers. It only happens with my LoginController. Perhaps this has something to do with the name of my class? |
Juergen Hoeller commented Guys, I can only re-express what I stated above: Please have a look at the source code of SimpleFormController. The onSubmit methods are called in the straight chain; there is no execution path that bypasses any of them. Please link in Spring's source code and use a debugger to step through your controller use case. The general rule is to only override one onSubmit method, though, not more than one. The base onSubmit methods are all implemented to delegate to next one with less arguments, so if you override one of them, the rest won't be called anymore. But this has already been recognized before (see the original post). I will reopen this issue if I receive a full test case that proves that SimpleFormController misbehaves with respect to the onSubmit chain. A static analysis of SimpleFormController does not show any potential that this can happen, though. In any case, I'm open to be proven wrong :-) Juergen |
Mark Aden commented I fixed my problem by making sure that the method signature of the onSubmit function is correct. It turned out that my errors object in the method signature was of type java.net.BindExceptions instead of org.springframework.validation.BindException. I suppose sometimes those handy IDE fix/organize imports feature can get you into trouble. Thanks Juergen for all your help. Keep up the good work and congrats on the success of Spring! |
Venkatt Guhesan opened SPR-692 and commented
I have a simple application where the following scenerio:
Within LoginController I override the following method:
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors)
throws Exception
on proper validation with no errors, I would expect the app to call the "onSubmit" method with the defined signature but it does not. If on the other hand I override, the following method:
protected ModelAndView onSubmit(Object command)
throws Exception
it calls the "onSubmit" method properly but I need to access the request scope to set a variable in the session.
Why does it not work when I implement the onSubmit(request,response,command,errors)? I have tried both Spring - 1.1.3 and 1.1.4 JARs.
PS: There is only one onSubmit method in the class. I have verified to make sure there were nother onSubmit methods...
Thanks
Venkatt Guhesan
Affects: 1.1.3, 1.1.4
Issue Links:
The text was updated successfully, but these errors were encountered: