Thursday, June 7, 2007

Accessing Request parameters in your Action class

1. Make your Action implement the ParameterAware interface.

2. Define a class variable for parameters Map:
private Map parameters;

3. Create getter and setter methods for the above defined parameters Map.

4. Calling getParameters() gives you access to the request parameters through the above defined Map.

5. To make things simple, you can create a getParameterValue() method to return value of a request parameter by its name:

public String getParameterValue(String param) {
Object varr = getParameters().get(param);
if (varr == null) return null;
return ((String[]) varr)[0];
}

1 comment:

Flightless Anonymous Bird said...

Thanks for this.. saved me a lot of time :)