2

How is it possible to get the message from key in the custom validator ?! As mentioned in Struts 2 - reusing Custom Expression Validator you can get default message as :

public void validate(Object o) throws ValidationException {

    //Do some logic
    addActionError(getDefaultMessage());
}
Community
  • 1
  • 1
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173

1 Answers1

2

Your custom validator should extend ValidatorSupport class, which has a convenient method getMessage(Object object) to get i18n messages set with key parameter.

So inside validate method instead of calling getDefaultMessage (which simple returns default message) call getMessage which will evaluate key parameter with additional messageParams.

public void validate(Object o) throws ValidationException {
    //Do some logic
    addActionError(getMessage(o));
}
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143