Search code examples
validationparametersstruts2interceptorprepare

struts2 prepare and validation


Im trying to ensure that when an action is called, the expected parameters are given (like to show a user profile I want to be sure that parameters contains the user id : viewUser.action?userId=1 should work well but viewUser.action should redirect to an error page)

So I created a validation xml that specifies that the userId field can not be null. Everything works fine.

But now, on prepare() I do some pre-work using the userId. The fact is that prepare interceptor is called before validation interceptor so if userId is null then I have a nice nullPointerException and the validation is not called because the error happened before. I know I can switch the interceptor order but I don't want to.

So my question is : Im I supposed to use parameters inside prepare() methods ? Is there any other way to handle that ?

Thanks and sorry for my bad english :(


Solution

  • Use the "paramsPrepareParamsStack" interceptor stack.