本文整理汇总了Java中org.apache.commons.validator.Validator.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java Validator.setParameter方法的具体用法?Java Validator.setParameter怎么用?Java Validator.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.Validator
的用法示例。
在下文中一共展示了Validator.setParameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initValidator
import org.apache.commons.validator.Validator; //导入方法依赖的package包/类
/**
* Initialize the <code>Validator</code> to perform validation.
*
* @param key The key that the validation rules are under (the
* form elements name attribute).
* @param bean The bean validation is being performed on.
* @param application servlet context
* @param request The current request object.
* @param errors The object any errors will be stored in.
* @param page This in conjunction with the page property of a
* <code>Field<code> can control the processing of
* fields. If the field's page is less than or equal
* to this page value, it will be processed.
*/
public static Validator initValidator(String key, Object bean,
ServletContext application, HttpServletRequest request,
ActionMessages errors, int page) {
ValidatorResources resources =
Resources.getValidatorResources(application, request);
Locale locale = RequestUtils.getUserLocale(request, null);
Validator validator = new Validator(resources, key);
validator.setUseContextClassLoader(true);
validator.setPage(page);
validator.setParameter(SERVLET_CONTEXT_PARAM, application);
validator.setParameter(HTTP_SERVLET_REQUEST_PARAM, request);
validator.setParameter(Validator.LOCALE_PARAM, locale);
validator.setParameter(ACTION_MESSAGES_PARAM, errors);
validator.setParameter(Validator.BEAN_PARAM, bean);
return validator;
}
示例2: initValidator
import org.apache.commons.validator.Validator; //导入方法依赖的package包/类
/**
* Initialize the <code>Validator</code> to perform validation.
*
* @param key The key that the validation rules are under (the form elements
* name attribute).
* @param bean The bean validation is being performed on.
* @param application servlet context
* @param request The current request object.
* @param errors The object any errors will be stored in.
* @param page This in conjunction with the page property of a
* <code>Field<code> can control the processing of fields. If the field's
* page is less than or equal to this page value, it will be processed.
*/
public static Validator initValidator(
String key,
Object bean,
ServletContext application,
HttpServletRequest request,
ActionMessages errors,
int page) {
ValidatorResources resources =
Resources.getValidatorResources(application, request);
Locale locale = RequestUtils.getUserLocale(request, null);
Validator validator = new Validator(resources, key);
validator.setUseContextClassLoader(true);
validator.setPage(page);
validator.setParameter(SERVLET_CONTEXT_PARAM, application);
validator.setParameter(HTTP_SERVLET_REQUEST_PARAM, request);
validator.setParameter(Validator.LOCALE_PARAM, locale);
validator.setParameter(ACTION_MESSAGES_PARAM, errors);
validator.setParameter(Validator.BEAN_PARAM, bean);
return validator;
}
示例3: fixLabels
import org.apache.commons.validator.Validator; //导入方法依赖的package包/类
public static void fixLabels(Object bean, ValidatorResources resources, String formName){
try{
Validator validator = new Validator(resources, formName);
validator.setParameter(Validator.BEAN_PARAM, bean);
validator.validate();
}catch(Exception e){
log.error(e);
}
}
示例4: validate
import org.apache.commons.validator.Validator; //导入方法依赖的package包/类
/**
* Validates the value of the specified Field on the target Object
*
* @param object
* @param fieldName
* @return a Set of Validation Error Keys
* @throws ValidationException
*/
public Set<String> validate(Object object, String fieldName)
throws ValidationException
{
try
{
Set<String> errorKeys = new HashSet<String>();
String objectId = object.getClass().getName();
//Setup the Validator
Validator validator = new Validator(this.validatorResources, objectId);
validator.setParameter(Validator.BEAN_PARAM, object);
validator.setFieldName(fieldName);
ValidatorResults results = validator.validate();
Form form = this.validatorResources.getForm(Locale.getDefault(), objectId);
Iterator propertyNames = results.getPropertyNames().iterator();
while(propertyNames.hasNext())
{
String property = (String)propertyNames.next();
ValidatorResult result = results.getValidatorResult(property);
Map actionMap = result.getActionMap();
Iterator keys = actionMap.keySet().iterator();
while (keys.hasNext())
{
String actionName = (String) keys.next();
if (!result.isValid(actionName))
{
Field field = form.getField(property);
Arg[] args = field.getArgs(actionName);
if(args != null)
{
for(int i=0; i<args.length; i++)
{
errorKeys.add(args[i].getKey());
}
}
}
}
}
return errorKeys;
}
catch(Exception e)
{
log.error(this, e);
throw new ValidationException(e);
}
}