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 :
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));
}