WithFormMethod (Grails 2.4.4)
Date: 2014-10-28

Package: org.codehaus.groovy.grails.web.metaclass

## [Groovy] Class WithFormMethod

- org.codehaus.groovy.grails.web.metaclass.WithFormMethod

- Implementation of the "Synchronizer Token Pattern" for Grails that handles duplicate form submissions by inspecting a token stored in the user session.

  Authors:
    Graeme Rocher
  Since:
    1.1

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `protected boolean` | `isTokenValid(GrailsWebRequest webRequest)` Checks whether the token in th request is valid.
    `protected java.lang.Object` | `resetToken(GrailsWebRequest webRequest)` Resets the token in the request
    `TokenResponseHandler` | `withForm(GrailsWebRequest webRequest, groovy.lang.Closure callable)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Method Detail

    - #### protected boolean isTokenValid(GrailsWebRequest webRequest)

      Checks whether the token in th request is valid.

      Parameters:
        `request` - The servlet request

    - #### protected java.lang.Object resetToken(GrailsWebRequest webRequest)

      Resets the token in the request

    - #### TokenResponseHandler withForm(GrailsWebRequest webRequest, groovy.lang.Closure callable)

      Main entry point, this method will check the request for the necessary TOKEN and if it is valid will call the passed closure.

      For an invalid response an InvalidResponseHandler is returned which will invoke the closure passed to the handleInvalid method. The idea here is to allow code like:

           withForm {
             // handle valid form submission
           }.invalidToken {
              // handle invalid form submission
           }