本文整理汇总了Java中org.apache.commons.validator.Form.getField方法的典型用法代码示例。如果您正苦于以下问题:Java Form.getField方法的具体用法?Java Form.getField怎么用?Java Form.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.Form
的用法示例。
在下文中一共展示了Form.getField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetupValidator
import org.apache.commons.validator.Form; //导入方法依赖的package包/类
/**
* @throws Exception
*/
public void testSetupValidator() throws Exception {
S2ActionMapping actionMapping = customizer
.createActionMapping(getComponentDef("aaa_bbbAction"));
customizer.setupValidator(actionMapping, validatorResources);
Form form = validatorResources.getForm(Locale.getDefault(),
"aaa_bbbActionForm_execute2");
assertNotNull(form);
org.apache.commons.validator.Field f = form.getField("hoge");
assertEquals("hoge", f.getProperty());
assertEquals("required", f.getDepends());
}
示例2: validate
import org.apache.commons.validator.Form; //导入方法依赖的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);
}
}
示例3: printResults
import org.apache.commons.validator.Form; //导入方法依赖的package包/类
/**
* Dumps out the Bean in question and the results of validating it.
*/
public static void printResults(
ValidateBean bean,
ValidatorResults results,
ValidatorResources resources) {
boolean success = true;
// Start by getting the form for the current locale and Bean.
Form form = resources.getForm(Locale.getDefault(), "ValidateBean");
System.out.println("\n\nValidating:");
System.out.println(bean);
// Iterate over each of the properties of the Bean which had messages.
Iterator<String> propertyNames = results.getPropertyNames().iterator();
while (propertyNames.hasNext()) {
String propertyName = propertyNames.next();
// Get the Field associated with that property in the Form
Field field = form.getField(propertyName);
// Look up the formatted name of the field from the Field arg0
String prettyFieldName = apps.getString(field.getArg(0).getKey());
// Get the result of validating the property.
ValidatorResult result = results.getValidatorResult(propertyName);
// Get all the actions run against the property, and iterate over their names.
Iterator<String> keys = result.getActions();
while (keys.hasNext()) {
String actName = keys.next();
// Get the Action for that name.
ValidatorAction action = resources.getValidatorAction(actName);
// If the result is valid, print PASSED, otherwise print FAILED
System.out.println(
propertyName
+ "["
+ actName
+ "] ("
+ (result.isValid(actName) ? "PASSED" : "FAILED")
+ ")");
//If the result failed, format the Action's message against the formatted field name
if (!result.isValid(actName)) {
success = false;
String message = apps.getString(action.getMsg());
Object[] args = { prettyFieldName };
System.out.println(
" Error message will be: "
+ MessageFormat.format(message, args));
}
}
}
if (success) {
System.out.println("FORM VALIDATION PASSED");
} else {
System.out.println("FORM VALIDATION FAILED");
}
}