this.numColumns = i;
}
public FormValidation validate() {
FormValidation outcome = new FormValidation();
for(FormItem item : items)
{
// two cases: empty form (create entity) and updating an existing entity
// we basically force validation on newly created entities
boolean requiresValidation = item.isModified();
if(requiresValidation)
{
Object value = item.getValue();
// ascii or empty string are ok. the later will be checked in each form item implentation.
String stringValue = String.valueOf(value);
boolean ascii = stringValue.isEmpty() ||
stringValue.matches("^[\\u0020-\\u007e]+$");
if(!ascii)
{
outcome.addError(item.getName());
item.setErroneous(true);
}
else
{
boolean validValue = item.validate(value);
if(validValue)
{
item.setErroneous(false);
}
else
{
outcome.addError(item.getName());
item.setErroneous(true);
}
}
}
}