@Override public String interpolate(String message, MessageInterpolator.Context context) { Locale locale = this.context.getViewRoot().getLocale(); if (locale == null) { locale = Locale.getDefault(); } return delegate.interpolate(message, context, locale); }
public <T> Validator addAll(Set<ConstraintViolation<T>> errors) { for (ConstraintViolation<T> v : errors) { String msg = interpolator.interpolate(v.getMessageTemplate(), new BeanValidatorContext(v), locale); String category = v.getPropertyPath().toString(); add(new SimpleMessage(category, msg)); logger.debug("added message {}={} for contraint violation", category, msg); } return this; }
@Test @TestForIssue(jiraKey = "HV-333") public void testContextWithRightDescriptorAndValueAndRootBeanClassIsPassedToMessageInterpolator() { // use a easy mock message interpolator for verifying that the right MessageInterpolatorContext // will be passed MessageInterpolator mock = createMock(MessageInterpolator.class); Configuration<?> config = ValidatorUtil.getConfiguration().messageInterpolator(mock); Validator validator = config.buildValidatorFactory().getValidator(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass(TestBean.class); PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty("test"); Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors(); assertTrue(constraintDescriptors.size() == 1); // prepare the mock interpolator to expect the right interpolate call String validatedValue = "value"; expect( mock.interpolate( MESSAGE, new MessageInterpolatorContext( constraintDescriptors.iterator().next(), validatedValue, TestBean.class, Collections.<String, Object>emptyMap()))) .andReturn("invalid"); replay(mock); Set<ConstraintViolation<TestBean>> violations = validator.validate(new TestBean(validatedValue)); assertNumberOfViolations(violations, 1); // verify that the right context was passed verify(mock); }
@Override public String interpolate(String messageTemplate, Context context, Locale locale) { String message = wrapped.interpolate(messageTemplate, context, locale); if (message.contains("{jsf.label}")) { String label = ""; if (hasContext()) { label = getLabel(getCurrentComponent()); } message = message.replace("{jsf.label}", label); } return message; }
@Override public String interpolate(String messageTemplate, Context context) { return wrapped.interpolate(messageTemplate, context); }
@Override public String interpolate(String message, MessageInterpolator.Context context, Locale locale) { return delegate.interpolate(message, context, locale); }
public String interpolate(String message, Context context, Locale locale) { String tmp = delegate.interpolate(message, context, locale); return interpolateMessage(tmp, context.getValidatedValue(), locale); }