*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
*/
public void validate(Object clazz, Errors e) {
UserDefinedField udf = (UserDefinedField) clazz;
ValidationUtils.rejectIfEmpty(e, "clazz", "error.required",
new Object[] { "Class" });
ValidationUtils.rejectIfEmptyOrWhitespace(e, "userField", "error.required",
new Object[] { "User Field" });
ValidationUtils.rejectIfEmptyOrWhitespace(e, "label", "error.required",
new Object[] { "Label" });
// there must be no duplicate field use per class
if (udf.getClass()!=null &&
!StringUtil.isEmpty(udf.getUserField()) ) {
UserDefinedField example = new UserDefinedField();
example.setUserField(udf.getUserField());
example.setClazz(udf.getClazz());
List<UserDefinedField> duplicate = userDefinedFieldService.findByExample(example, true);
if (duplicate!=null && !duplicate.isEmpty()
&& !duplicate.get(0).getId().equals(udf.getId())) {
e.reject("error.duplicate-field",
new Object[]{udf.getClazz().getSimpleName() + " " + udf.getUserField(), "field"},