当前位置: 首页>>代码示例>>Java>>正文


Java Form.getField方法代码示例

本文整理汇总了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());
}
 
开发者ID:seasarorg,项目名称:sa-struts,代码行数:15,代码来源:ActionCustomizerTest.java

示例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);
	}
}
 
开发者ID:ZalemSoftware,项目名称:OpenMobster,代码行数:58,代码来源:ObjectValidator.java

示例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");
    }

}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-validator,代码行数:67,代码来源:ValidateExample.java


注:本文中的org.apache.commons.validator.Form.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。