Groovy Documentation

org.codehaus.groovy.grails.web.metaclass
[Groovy] Class WithFormMethod

java.lang.Object
  org.codehaus.groovy.grails.web.metaclass.WithFormMethod

class 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


Method Summary
protected boolean isTokenValid(HttpServletRequest request)

Checks whether the token in th request is valid.

protected java.lang.Object resetToken(HttpServletRequest request)

Resets the token in the request

TokenResponseHandler withForm(HttpServletRequest request, 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.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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

isTokenValid

protected boolean isTokenValid(HttpServletRequest request)
Checks whether the token in th request is valid.
Parameters:
request - The servlet request


resetToken

protected java.lang.Object resetToken(HttpServletRequest request)
Resets the token in the request


withForm

TokenResponseHandler withForm(HttpServletRequest request, 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
 }
 


 

Groovy Documentation