Skip to content
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

Closed
spring-projects-issues opened this issue Feb 5, 2005 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 5, 2005

Venkatt Guhesan opened SPR-692 and commented

I have a simple application where the following scenerio:

  • LoginController extends SimpleFormController
  • LoginValidator implements Validator

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:

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Closed for the time being. To be reopened if the issue is reproducible in specific scenarios.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 17, 2005

Venkatt Guhesan commented

I had a few people email me with the same issue and here's what I have discovered:

#1:
onSubmit(Object object) gets called when there are NO VALIDATION ERRORS

#2:
onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) and

#3:
onSubmit(Object command, BindException errors) gets called when there are VALIDATION ERRORS

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:
processFormSubmission(HttpServletRequest request,
HttpServletResponse response, Object object,
org.springframework.validation.BindException errors) which gets invoked in either case, I can then check to see if the method signature contains any errors. If no errors then process what I need to do to place things in Session scope.

Here is an example that might help explain this:
public class LoginController extends SimpleFormController
...
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object object, org.springframework.validation.BindException errors) throws Exception
{
Login login = (Login) object;

if (errors.getErrorCount() == 0)
{
    request.getSession().setAttribute("login", login);            
}
else
{
    //do something else...
}
return super.processFormSubmission(request,response,object,errors);

}


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###@Y!.com w/o the pound and replace Y! with appropriate domain!!! ;-)

Venkatt

@spring-projects-issues
Copy link
Collaborator Author

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?

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)
Projects
None yet
Development

No branches or pull requests

2 participants