How to build a breadcrumb with Spring Webflow 1.0.4
In this tutorial we explain how to create a simple breadcrumb with the new Spring Webflow framework, arrived at 1.0.4 version, released the 26 June 2007.
The first step is creating a class that implements FlowExecutionListener, a WebFlow framework library:
public class BreadcrumbListener implements FlowExecutionListener { }
Then, you can override one of the next two methods defined in the superclass (from the WebFlow API docs):
void requestProcessed(RequestContext context)
Called when a client request has completed processing.
void requestSubmitted(RequestContext context)
Called when any client request is submitted to manipulate this flow execution.
For our requirements, the best choise is the first requestProcessed.
Now you can build the complete url requested by the user, with the context parameter input of the requestProcessed method:
ParameterMap requestParameters =
context.getRequestParameters();
Map requestParametersMap = requestParameters.asMap();
// We rebuild the query string iterating all the parameter
Iterator iter = requestParametersMap.keySet().iterator();
ExternalContext externalContext = context.getExternalContext();
// The context path of web application
String contextPath = externalContext.getContextPath();
// The relative URI of the request submitted
String requestPathInfo = externalContext.getRequestPathInfo();
With a cancatenation of previus values, you can save the complete Url requested (for ex: http://www.mywebapp.com/action?param1=value1) in a String called for example lastCompleteUrl.
Now we load the current Breadcrumb that we have serialized in flow scope, and if ther isnt any, we instantiate a new ordered data structure:
LinkedHashMap breadCrumb = new LinkedHashMap();
In the next step, you add the last url (you have built in previus step) to the breadCrumb data structure. One breadCrumb’s item must contain al least 2 information: the last state id, and the state caption. For this reason is preferible to create an object that encapsulate these informations. Now the code:
// We load the last state id
StateDefinition currentState = context.getCurrentState();
if (currentState != null && currentState instanceof ViewState) {
// Save the last state info in a custom object
BreadcrumbElement breadcrumbElement =
new BreadcrumbElement(currentState.getId(), getStateCaption(currentState));
getStateCaption is explained here. Then you add the step tu BreadCrumb:
if (breadCrumb.get(breadcrumbElement) == null) {
breadCrumb.put(breadcrumbElement, lastCompleteUrl);
} else {
// You must delete the duplicated elements
}
That’s all. Is it clear?

[…] How to build a breadcrumb with Spring Webflow 1.0.4 - In this tutorial we explain how to create a simple breadcrumb with the new Spring Webflow framework, arrived at 1.0.4 version, released the 26 June 2007. […]
[…] How to build a breadcrumb with Spring Webflow 1.0.4 - In this tutorial we explain how to create a simple breadcrumb with the new Spring Webflow framework, arrived at 1.0.4 version, released the 26 June 2007. […]