// prefix Code =====================================================
TextField prefixCode = new TextField("space.prefixCode");
prefixCode.setRequired(true);
prefixCode.add(new ErrorHighlighter());
// validation: greater than 3 chars?
prefixCode.add(new AbstractValidator() {
protected void onValidate(IValidatable v) {
String s = (String) v.getValue();
if(s.length() < 3) {
error(v);
}
}
@Override
protected String resourceKey() {
return "space_form.error.prefixCode.tooShort";
}
});
prefixCode.add(new AbstractValidator() {
protected void onValidate(IValidatable v) {
String s = (String) v.getValue();
if(s.length() > 10) {
error(v);
}
}
@Override
protected String resourceKey() {
return "space_form.error.prefixCode.tooLong";
}
});
// validation: format ok?
prefixCode.add(new AbstractValidator() {
protected void onValidate(IValidatable v) {
String s = (String) v.getValue();
if(!ValidationUtils.isValidSpaceKey(s)) {
error(v);
}
}
@Override
protected String resourceKey() {
return "space_form.error.prefixCode.invalid";
}
});
// validation: does space already exist with same prefixCode ?
prefixCode.add(new AbstractValidator() {
protected void onValidate(IValidatable v) {
String s = (String) v.getValue();
Space temp = getJtrac().loadSpace(s);
if(temp != null && temp.getId() != space.getId()) {
error(v);