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 Stripecube Show documentation
Show all versions of Stripecube Show documentation
Stripecube is an open source Java framework for Web Applications
package com.clickntap.tool.bean;
import com.clickntap.tool.script.ScriptEngine;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
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());
}
}
}