Using a request parameter in Spring Webflow



Given a complete web application build on Spring Webflow, that is used as an internal application. Imagine that you are a customer calling a general phonenumber from the company, and you fill in your customer number. At the back office there is a special software catching the customer number and redirecting the request to the customer desk together with a GET request to the internal Webflow application like

http://{domain}/{context root}/customerprofile?customernumber=123456

The customer service employee who takes the call, receives a response from the system with the above link and will be automatically redirected to the customer profile page inside the internal application.

For this particular situation we can build a simple POJO that is called inside the customerprofile.xml Webflow to get the parameter value from the URL and pass it over to the flowScope. Inside the customerprofile.xml we use at the beginning of the code


<var name="requestParamUtil" class="nl.yenlo.beans.support.RequestUtil" />

to define a variable in Webflow. And


<on-start>
<evaluate expression="requestParamUtil.getRequestParameter('customernumber', externalContext)" result="flowScope.custnr"/>
</on-start>


to create a handler for catching the request. Notice the externalContext variable. This is a predefined variable inside Webflow for the ExternalContext class. The requestParamUtil POJO looks like


package nl.yenlo.beans.support;

import java.io.Serializable;
import org.springframework.webflow.context.ExternalContext;

/**
*
* @author sliem
*/
public class RequestUtil implements Serializable {

public String getRequestParameter(String name, ExternalContext context) {
try{
String paramValue = context.getRequestParameterMap().get(name);
return paramValue ;
}catch(Exception e){
e.printStackTrace();
return "";
}
}

}

So when you execute the predefined URL inside a browser, Webflow goes directly to the flow getting the parameter value, only if there is one.

Comments are closed.

  • 071 - 82 000 82
  • Rijndijk 137 | 2394 AG Hazerswoude-Rijndijk
DEMO
Oracle Specialized
Java
GlassFish
WSO2
i-bridge
Rabobank
Greencat
Reuma Revalidatie Rotterdam
Robeco
VU Medisch Centrum
CHS
LUMC
TomTom
TKP
NCCW
Erasmus MC
UMCG
VIR
ANWB
BVA Auctions
D-Reizen
STEDIN