validationstruts2struts-validation

Struts 2 validation xml vs validate method


Hello guys I'm a application engineer working on J2EE technologies, Recently I have got one requirement where I have to show some dynamic fields on input page which will come from Ajax call and can be 1 to n, i.e. their names are not fixed, so I can not make them as form field.

I'm able to do that but next thing is validation. As I can not make them as form field so I'm validating those in validate method inside action class. I have one doubt which is..

Suppose my Struts validation contains other validation rules for rest of the form fields and suppose I have kept short circuit as false and validation xml returns false, then the validate method inside the action will be executed or not? or the work flow interceptor will directly return from struts-validation.xml without executing my validate method?


Solution

  • By default it's executed, unless you configure the interceptor parameter to false:

    • alwaysInvokeValidate - Defaults to true. If true validate() method will always be invoked, otherwise it will not.

    For other parameters see Validation Interceptor.