Daud
Daud

Reputation: 7887

Struts2 - How to find errors found during xml validation in the validate method?

I believe that if both - xml validation, and validation in the action class are setup, then, irrespective of whether errors were discovered in the xml validation phase, the action class' validate method will be called. Building on this premise, how can I know that there were any xml validation errors from inside my action's validate() method (getActionErrors().size() == 0.. something like that).

My purpose is to set certain variables of the action class if there were validation errors before sending control back to the jsp. (setting them inside prepare would be wrong, as prepare would execute irrespective of whether there were errors)

Upvotes: 1

Views: 1073

Answers (1)

nmc
nmc

Reputation: 8696

You can use getFieldErrors() which returns

Map with errors mapped from fieldname (String) to Collection of String error messages

There are also helper methods such as hasActionErrors() and hasFieldErrors() which will help you determine if errors already exist.

Note that the first tells you if there are Action-level errors and the latter helps determine if there are specific, field associated errors.

Upvotes: 4

Related Questions