Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle form re-submission in spring-mvc-3

 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Any suggestions on how to handle form re-submission in Spring MVC 3 with annotations.
I tried implementing Post-Rediect-Get design pattern but it doesnt work in IE and once Get request crosses it's no. of character in request string it stops working in mozilla as well.
Any tutorial or Blog Or suggestion please.

Thanks,
Mahesh
 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone to help please.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Sounds like you are doing something wrong. What kind of page are you trying to redirect to? Typically it would be a success page or the same page but with a success message. Where all the extra parameters coming from? Post some code so we can see what you are trying to do.
 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,

Thanks for your reply.

Well, I've a report page getUserDetails.jsp which has form fields such as username, startdate and enddate, producttype.
User fill all these fields clicks on submit. Application displays a report to the user accordingly which is displayed using jqGrid. Therefore I'm passing JSONString to jsp page.
Code looks something like this:



Well, what are the various ways using which we can avoid double form submission in spring mvc 3.0??
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well at first glance it looks like when you are posting in you are adding a userlist to the model before redirecting to the get. All of those parameters are going to translate into URL parameters, which is why you are getting the error.

One thing you could do is have the GET method look up the user list and return it rather than having the POST method place it on the model. If you need to pass some additional message information to the page you can also make use of RedirectAttributes.

Typically on the POST method you would either have a BindingResult or a @Valid or implement the Validator interface and only do the redirect if the BindingResult does not have errors otherwise you would return them to the form. Otherwise on an erroneous form submission they will be re-directed and will be unable to rectify the problem.

Below is a blog on using the RedirectAttributes
http://vard-lokkur.blogspot.com.es/2012/02/spring-mvc-flash-attributes.html

 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

But somehow "redirect:PATH" doesn't work in IE 8.0.7600.16385.
Any specific reason behind that if anyone knows.

Also apart from Post-Redirect-Get pattern is there any other way to handle double submission of form(normal which happens when user refreshes page using F5 or clicking refresh button).

Thanks,
Mahesh
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
redirect works just fine in IE 8 on all of my projects is there a particular exception your are getting? If so please post it. That is the pattern that is used to handle that particular issue. Did you read the link I gave?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic