0

I am using Struts2 and an action implementing the Preparable interface.

When I submit the form, action properties are not being set in prepare() method of action. I get the values in the action method (eg. execute()), but they are empty in the prepare() method.

How can I get the properties set before running the prepare() method ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Kalpesh
  • 89
  • 1
  • 11

1 Answers1

1

In the default Interceptor Stack, the Prepare Interceptor runs before the Parameters Interceptor. That means that the injection of parameters has not yet occurred when the Prepare Interceptor executes the prepare() method. You need to move the Parameters Interceptor before the Prepare Interceptor, or to duplicate it, putting one declaration before the Prepare Interceptor.

There is a default Interceptor Stack created with that purpose, paramsPrepareParamsStack; read more here and here.

Note that this kind of problem is recurrent in Struts2, you need to understand how an Interceptor Stack works and which business every single Interceptor is taking care of.

For example, it happens when using ModelDriven, or when using Wildcard Mapping. And for sure it happens with your custom Interceptor if you put them in the wrong place.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243