Skip to content

Commit

Permalink
WW-4202 Solves problem with using wrong TextProvider for ModelDriven
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Mar 28, 2014
1 parent 3e2c60f commit a6017dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,32 @@ public boolean hasFieldErrors() {
public static TextProvider makeTextProvider(Object object, LocaleProvider localeProvider) {
// the object argument passed through here will most probably be an ActionSupport decendant which does
// implements TextProvider.
if (object != null && object instanceof DelegatingValidatorContext) {
return ((DelegatingValidatorContext) object).getTextProvider();
} else if (localeProvider != null && localeProvider instanceof DelegatingValidatorContext) {
return ((DelegatingValidatorContext) localeProvider).getTextProvider();
}

if ((object != null) && (object instanceof TextProvider)) {
if (object instanceof CompositeTextProvider) {
return (CompositeTextProvider) object;
}
return new CompositeTextProvider(new TextProvider[]{
((TextProvider) object),
new TextProviderSupport(object.getClass(), localeProvider)
});
} else if (localeProvider != null && localeProvider instanceof TextProvider) {
if (localeProvider instanceof CompositeTextProvider) {
return (CompositeTextProvider) localeProvider;
}
return new CompositeTextProvider(new TextProvider[]{
((TextProvider) localeProvider),
new TextProviderSupport(localeProvider.getClass(), localeProvider)
});
} else {
return new TextProviderFactory().createInstance(object.getClass(), localeProvider);
return new TextProviderFactory().createInstance(
object != null ? object.getClass() : DelegatingValidatorContext.class,
localeProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testBeanMessagesUseBeanResourceBundle() throws Exception {
assertEquals(1, beanCountMessages.size());

String beanCountMessage = beanCountMessages.get(0);
assertEquals("bean: Count must be between 1 and 100, current value is -1.", beanCountMessage);
assertEquals("bean: Invalid count value, must be between 1 and 100, current value -1!", beanCountMessage);
}

public void testCollectionValidation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<field-validator type="int" short-circuit="true">
<param name="min">1</param>
<param name="max">100</param>
<message key="invalid.count">Invalid Count!</message>
<message key="invalid.count">Invalid count value, must be between ${min} and ${max}, current value ${count}!</message>
</field-validator>
<field-validator type="int">
<param name="min">20</param>
Expand Down

0 comments on commit a6017dc

Please sign in to comment.