Custom Method Validator
I am currently having problems with creating a custom method validator within the business component framework. I have a simple method in the PostImpl (EntityImpl) java file which checks if one date is after another, if (and only if) the second date is present.
The code is detailed below:
public boolean validatePostStartDate(Date postStartDate)
{
Date postEndDate = this.getPostEndDate();
if(postEndDate == null)
{
return true;
}
else
{
java.sql.Date startDate = (java.sql.Date)postStartDate.dateValue();
java.sql.Date endDate = (java.sql.Date)postEndDate.dateValue();
if(startDate.after(endDate))
return false;
else
return true;
}
}
The code works fine and the validation is executed correctly, but it is the error message with which I am having difficulty. The message which was entered in the 'Error Message' field of the 'Entity Object Wizard-Edit Validation Rule for: PostStartDate' dialog is being updated in both the PostImplMsgBundle (JboResourceBundle) and in the Post XML file:
static final Object[][] sMessageStrings = {{"PostStartDate_Rule_0", "The start date must be before the end date of the post"}};
and
<MethodValidationBean
ResId="PostStartDate_Rule_0"
MethodName="validatePostStartDate" >
</MethodValidationBean>
The error message that is shown on failure of the validation is:
JBO-27013: Attribute set validation method validatePostStartDate failed for attribute PostStartDate in Post
After entering the error message in the dialog, it subsequently disappears from the field, but remains within the java and XML files.
The other rules work fine (CompareValidator,ListValidator and RangeValidator) and fetch the correct error message as detailed in the dialog.
I don't wish to use the 'Custom Attribute Validation' technique of adding custom code and throwing my own JboException in the set method of the attribute with which I am validating, mainly due to the fact I need to use standard validation code for different attributes.
Can anyone shed any light on this rather strange problem?
Any info will be gratefully recieved.
Thanks
Paul Cartmell.