7

Grails - Duplicate Form Submission Processing - How does withForm {} work?

 9 months ago
source link: https://www.codesd.com/item/grails-duplicate-form-submission-processing-how-does-withform-work.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Grails - Duplicate Form Submission Processing - How does withForm {} work?

advertisements

I am trying to handle duplicate form submission in my Grails app. So I set useToken="true" in my form, and this is how I try to use the withForm method in my controller:

def myControllerAction {
    withForm {
       *my action's logic*
    }
}

However, I end-up with: Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects. in my browser. So I guess I am not using it right, and I have not found any example on the web on how to use the method properly.

Any help on this would be very helpful. Thanks you in advance.


You don't really have much in your example: the short answer is that you must be doing something to cause redirects if the token is invalid.

The Grails Manual shows how to use it.

All the logic does is put a hidden field with a unique value in it. That value is stored in the session, so your sessions must be working correctly (and you need session affinity or shared session if hosting in a clustered environment). When the form is submitted, it looks for that unique value, and determines if it's already been submitted or not.

You don't appear to be handling an invalidToken anywhere, so you might be dealing with a situation where the token isn't being stored or passed correctly, and your logic is causing a redirect. If you are redirecting using a get instead of a post, this could be causing a redirect loop. (This may cause a redirect loop even if the token is processed correctly the first time.)

I would look at your code and figure out where the redirect is coming from. It isn't caused by the token directly.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK