Hi, I see what happens. form.getString() would work because of https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/resource/loader/ValidatorStringResourceLoader.java#L100 But using ValidationError has no reference to the form, and thus its form validators, and it fails.
Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Wed, Oct 1, 2014 at 7:04 PM, msalman <mohammad_sal...@yahoo.com> wrote: > Hi Martin, > > Thanks for your help. That worked but I had to do a few extra things such > as setting the values for '${label0}', etc. What I don't get is why do we > need to do this extra thing for Form validation classes (extending > AbstractFormValidator) but not for component validation classes > (implementing IValidator). > > > > For others who may face the same problem, this is how got it working: > > > @Override > public void validate(Form<?> form) > { > Date fromDate = fromDateFormComponent.getConvertedInput(); > Date toDate = toDateFormComponent.getConvertedInput(); > > if ( fromDate != null > && toDate != null > && fromDate.after(toDate)) > { > ClassStringResourceLoader loader = new > ClassStringResourceLoader(FromDateBeforeToDate.class); > > > Application.get().getResourceSettings().getStringResourceLoaders().add(loader); > I hope this is not your real code for production. This will add the loader to the list of loaders on every validation. > > ValidationError error = new ValidationError(); > error.addMessageKey(getClass().getSimpleName() + > "." + > "fromDateAfterToDate"); > error.setVariable("label0", > fromDateFormComponent.getLabel().getObject()); > error.setVariable("label1", > toDateFormComponent.getLabel().getObject()); > > > fromDateFormComponent.newValidatable().error(error); > } > } > > > > FromDateBeforeToDate.properties > > FromDateBeforeToDate.fromDateAfterToDate=Invalid input: The '${label}' date > is after the '${label}' date > > > I thank you again for teh quick and helpful response. > > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/FormValidators-and-messages-property-file-tp4667767p4667783.html > Sent from the Users forum mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >