com.ervacon.springframework.web.servlet.mvc.webflow
Class WebFlowUtils

java.lang.Object
  extended bycom.ervacon.springframework.web.servlet.mvc.webflow.WebFlowUtils

public class WebFlowUtils
extends java.lang.Object

Static utility methods used by the Spring web flow system and applications that use it.

This class provides web transaction token handling methods similar to those available in the Struts framework. In essense an implementation of the synchronizer token pattern. You can use this to prevent double submits in the following way:

Author:
Erwin Vervaet

Method Summary
static java.lang.String generateUniqueId()
          Generate a pseudo unique id.
static WebFlowMementoStack getWebFlowMementoStack(javax.servlet.http.HttpServletRequest request, java.util.Map model)
          Retreive the web flow memento stack for the currently executing flow.
static WebFlowMementoStack getWebFlowMementoStack(javax.servlet.http.HttpServletRequest request, java.util.Map model, java.lang.String flowIdModelName)
          Retreive the web flow memento stack for the currently executing flow.
static boolean isTokenValid(java.util.Map model, java.lang.String tokenName, javax.servlet.http.HttpServletRequest request, java.lang.String requestTokenName, boolean reset)
          Return true if there is a transaction token stored in given model, and the value submitted as a request parameter with this action matches it.
static void resetToken(java.util.Map model, java.lang.String tokenName)
          Reset the saved transaction token in given model.
static void saveToken(java.util.Map model, java.lang.String tokenName)
          Save a new transaction token in given model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

generateUniqueId

public static java.lang.String generateUniqueId()

Generate a pseudo unique id. This implementation uses the system time and a random number to generate an id. The generated id should be unique enough for flow ids or tokens, but it is certainly not a globally unique id.


getWebFlowMementoStack

public static WebFlowMementoStack getWebFlowMementoStack(javax.servlet.http.HttpServletRequest request,
                                                         java.util.Map model)

Retreive the web flow memento stack for the currently executing flow. This method will first obtain the id of the currently executing flow from given model using the WebFlowController.FLOW_ID_MODEL_NAME name. With this id, it will get the flow memento stack from the session associated with given request.

Parameters:
request - current HTTP request
model - model of the flow
Returns:
the memento stack of the currently executing flow

getWebFlowMementoStack

public static WebFlowMementoStack getWebFlowMementoStack(javax.servlet.http.HttpServletRequest request,
                                                         java.util.Map model,
                                                         java.lang.String flowIdModelName)

Retreive the web flow memento stack for the currently executing flow. This method will first obtain the id of the currently executing flow from given model using the given name. With this id, it will get the flow memento stack from the session associated with given request.

Use this method if you changed the name of the flow id in the model using the WebFlowController.setFlowIdModelName(String) method.

Parameters:
request - current HTTP request
model - model of the flow
flowIdModelName - name of the flow id in the model
Returns:
the memento stack of the currently executing flow

saveToken

public static void saveToken(java.util.Map model,
                             java.lang.String tokenName)

Save a new transaction token in given model.

Parameters:
model - the model map where the generated token should be saved
tokenName - the key used to save the token in the model map

resetToken

public static void resetToken(java.util.Map model,
                              java.lang.String tokenName)

Reset the saved transaction token in given model. This indicates that transactional token checking will not be needed on the next request that is submitted.

Parameters:
model - the model map where the generated token should be saved
tokenName - the key used to save the token in the model map

isTokenValid

public static boolean isTokenValid(java.util.Map model,
                                   java.lang.String tokenName,
                                   javax.servlet.http.HttpServletRequest request,
                                   java.lang.String requestTokenName,
                                   boolean reset)

Return true if there is a transaction token stored in given model, and the value submitted as a request parameter with this action matches it. Returns false when

Parameters:
model - the model map where the token is stored
tokenName - the key used to save the token in the model map
request - current HTTP request
requestTokenName - name of the request parameter holding the token
reset - indicates whether or not the token should be reset after checking it
Returns:
true when the token is valid, false otherwise