Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The request parameters are available on the ActionContext instance, which is made available via ThreadLocal.

Code Block

Map parameters = ActionContext.getContext().getParameters();

Implement

...

HttpParametersAware

(star) Preferred

  • Ensure that servlet-config Interceptor is included in the Action's stack.
    • (info) The default stack already includes servlet-config.
  • Edit the Action so that it implements the ParameterAware HttpParametersAware interface.
    • The ParameterAware HttpParametersAware interface expects a setParameters method. You may wish to include a companion getParameters method.
  • At runtime, call getParameters to obtain a Map an object representing the request parameters.
Code Block

Map parameters = this.getParameters();

 

Info

When the servlet-config Interceptor sees that an Action implements ParameterAware, it passes a Map of the request parameters to the Action's setParameters method.

Tip

To unit test a ParameterAware Action, create your own Map with the pertinent request parameters and call setParameters as part of the test's setUp method.

@see see struts-default.xml
@see org.apache.struts.action2.interceptor.ParameterAware
@see  and org.apache.struts.action2.interceptor.Servlet Config Interceptor