Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

FormValidators and messages property file

$
0
0
Hi,

I have created form validator classes as shown below. The problem is that
the code is not picking up messages from the corresponding
'FromDateBeforeToDate.properties' file in the same package. It works if the
messages are in the page.properties or application.properties file.

I can see works OK for class implementing IValidator but can't seem to make
it work for class extending AbstractFormValidator. Are my expectations
wrong? If not then please tell me how I can fix the code.

public class FromDateBeforeToDate extends AbstractFormValidator

/**

*/
private static final long serialVersionUID = 3503966266288025266L;

DateField fromDateFormComponent;
DateField toDateFormComponent;

public FromDateBeforeToDate(
DateField fromDateFormComponent,
DateField toDateFormComponent)

if (fromDateFormComponent == null)

throw new IllegalArgumentException("Argument dateFromFormComponent cannot
be null");

this.fromDateFormComponent = fromDateFormComponent;

if (toDateFormComponent == null)

throw new IllegalArgumentException("Argument dateToFormComponent cannot
be null");

this.toDateFormComponent = toDateFormComponent;

@Override
public FormComponent<?>[] getDependentFormComponents()

return new FormComponent<?>[]

fromDateFormComponent,
toDateFormComponent,
};

@Override
public void validate(Form<?> form)

Date fromDate = fromDateFormComponent.getConvertedInput();
Date toDate = toDateFormComponent.getConvertedInput();

if ( fromDate != null
& toDate != null
& fromDate.after(toDate))

//error(fromDateFormComponent, "fromDateAfterToDate");

ValidationError error = new ValidationError();
error.addMessageKey(getClass().getSimpleName() + "." +
"fromDateAfterToDate");
fromDateFormComponent.newValidatable().error(error);
//this.error(fromDateFormComponent);

FromDateBeforeToDate.properties

#fromDateAfterToDate=Invalid input: The '${label}' date is after the
'${label}' date
FromDateBeforeToDate.fromDateAfterToDate=Invalid input: The '${label}' date
is after the '${label}' date

Thanks.

Viewing all articles
Browse latest Browse all 5648

Trending Articles