I have a webapp written with the Spring Framework, Velocity, and (in part) Spring Web Flow.
In order to provide a common set of references in all my web pages for my velocity template, I have written a FlowExecutionListener which looks like this:
@Override
public void requestSubmitted(RequestContext context)
{
Map<String, Object> model = new HashMap<String, Object>();
populateModel(model);
context.getRequestScope().putAll(new LocalAttributeMap(model));
}
I can then access the keys stored in the model as Velocity references, e.g. $reference.
In general, this works great.
However, certain exit points from the flow will redirect to a GET request, like so:
<view-state id="startOver" view="redirect:/new"/>
These redirects will do a 302 to a new request, with all the request attributes turned into URL parameters, resulting in a big unwieldy URL instead of the clean /new url I was trying to redirect to.
I would like to detect in the listener when the flow is returning a redirect, so that I can skip the storing of the strings in the request attributes. (I do this with an interceptor with standard Spring MVC by matching whether the view name starts with “redirect:” ). But I can’t seem to find a way in the listener to detect this.
Alternately, are there other ways to prevent the request attributes from being put on the URL after a redirect?
You can use a custom FlowUrlHandler which builds the URL for the redirect. The best way to see how to implement it is to look at the code of DefaultFlowUrlHandler, but the main idea for you problem is to filter the input from the flowDefinitionUrl, for example:
To use it, use this Spring configuration: