com.clickntap.tool.bean.BeanValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of click_framework Show documentation
Show all versions of click_framework Show documentation
Java Framework based on Spring Framework, Freemarker and Simplicity
package com.clickntap.tool.bean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import com.clickntap.tool.script.ScriptEngine;
public class BeanValidator implements Validator {
private BeanInfo beanInfo;
private ScriptEngine viewEngine;
private String validationGroup;
private BeanManager beanManager;
public BeanValidator(BeanInfo beanInfo, ScriptEngine viewEngine, String validationGroup, BeanManager beanManager) {
this.beanInfo = beanInfo;
this.viewEngine = viewEngine;
this.validationGroup = validationGroup;
this.beanManager = beanManager;
}
public boolean supports(Class clazz) {
return true;
}
public void validate(Object target, Errors errors) {
Map context = new HashMap();
try {
context.put("target", target);
context.put("this", new BeanErrors(target, errors, beanManager));
List scriptList = beanInfo.getValidationInfo().getValidationScriptList(validationGroup);
for (String script : scriptList)
viewEngine.evalScript(context, script);
} catch (Exception e) {
errors.reject("validation", e.getMessage());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy