Possible Duplicate:
Dependency injection in FacesValidator (JSF Validation)
Maybe, I'm missing something basic - but can't I use injection in a custom validator class in order to use the message resources? The following code gives me a null on msg
, so injection obviously does not work, but why? And if it's not possible, how can I access the message resources? All examples I found so far, use hard coded text in validator messages which is not very useful for localization.
public class BirthdateValidator implements Validator {
@Inject
private transient ResourceBundle msg;
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if ( [some validation fails] ) {
FacesMessage message = new FacesMessage(msg.getString("validator.birthday"));
message.setSeverity(FacesMessage.SEVERITY_ERROR);
}
}
}