我想传递 ResourceBundle 的 (globalmessage.properties) 属性名称“ atm.number ”而不是硬编码文本“Número de cajero”作为“ errors.required ”属性的参数。我将如何在验证器中做到这一点?
ReporteIncidenciaValidator(验证器):
public class ReporteIncidenciaValidator implements Validator {
public boolean supports(Class<?> clazz) {
return ReporteIncidencia.class.isAssignableFrom(clazz);
}
public void validate(Object target, Errors errors) {
ReporteIncidencia reporteIncidencia = (ReporteIncidencia) target;
if (StringUtils.isBlank(reporteIncidencia.getNumeroCajero())) {
errors.rejectValue("numeroCajero", "errors.required",
new Object[]{"Número de cajero"}, "");
}
}
}
globalmessage.properties:
errors.required={0} es requerido.
atm.number=Número de cajero
servlet-context.xml:
...
<beans:bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="classpath:globalmessages" />
</beans:bean>
...