Example usage for org.apache.commons.validator Arg getKey

List of usage examples for org.apache.commons.validator Arg getKey

Introduction

In this page you can find the example usage for org.apache.commons.validator Arg getKey.

Prototype

public String getKey() 

Source Link

Document

Gets the key/value.

Usage

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java

/**
 * wIndextB?[h?B/*from  w w w  .j av a2 s  . c o  m*/
 * 
 * <b>?\bhANVtH?[? tH?[O?Ap?s???B</b>
 * 
 * @param field
 *            utB?[hIuWFNg
 * @param pos
 *            ?CfbNX
 * @return u?tB?[hIuWFNg
 */
protected static Field getArrayIndexField(Field field, int pos) {
    Field cloneField = (Field) field.clone();

    // ##index?A?vf??
    Arg argParam = null;
    String argStr = null;

    argParam = cloneField.getArg(0);
    if (argParam != null) {
        argStr = argParam.getKey();
        cloneField.getArg(0).setKey(replaceIndexString(argStr, pos + 1));
    }

    argParam = cloneField.getArg(1);
    if (argParam != null) {
        argStr = argParam.getKey();
        cloneField.getArg(1).setKey(replaceIndexString(argStr, pos + 1));
    }

    argParam = cloneField.getArg(2);
    if (argParam != null) {
        argStr = argParam.getKey();
        cloneField.getArg(2).setKey(replaceIndexString(argStr, pos + 1));
    }

    argParam = cloneField.getArg(3);
    if (argParam != null) {
        argStr = argParam.getKey();
        cloneField.getArg(3).setKey(replaceIndexString(argStr, pos + 1));
    }

    return cloneField;
}

From source file:org.megatome.frame2.validator.CommonsFieldValidator.java

/**
 * Add an error to the Errors object//from   w  ww.j  a  v a2  s. co  m
 * 
 * @param va
 *            Validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to use when creating the Error
 * @param validatorErrorValue1
 *            First error value to use
 * @param validatorErrorValue2
 *            Second error value to use
 */
protected static void addError(ValidatorAction va, Errors errors, Field field, Object validatorErrorValue1,
        Object validatorErrorValue2) {
    Arg arg = field.getArg(0);
    String validatorKey = va.getMsg();
    if (arg != null) {
        String fieldMsgKey = arg.getKey();
        if (fieldMsgKey != null) {
            Error fieldMsg = ErrorFactory.createError(fieldMsgKey);
            Error validateError = ErrorFactory.createError(validatorKey, fieldMsg, validatorErrorValue1,
                    validatorErrorValue2);
            errors.add(validateError);
        }
    }
}

From source file:org.megatome.frame2.validator.CommonsFieldValidator.java

/**
 * Validate the contents of two fields to verify that they match. This is
 * useful for comparing a password and a confirmation value, for instance.
 * /*from  www  .j  a  v a  2s.  co  m*/
 * @param bean
 *            The event containing the fields to validate
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The first field to validate
 * @return True if the first field is null, or if the first and second
 *         fields contain identical values.
 */
public static boolean validateTwoFields(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String sProperty2 = field.getVarValue("secondProperty"); //$NON-NLS-1$
    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);
    if (!GenericValidator.isBlankOrNull(value)) {
        try {
            if (!value.equals(value2)) {
                Arg arg = field.getArg(1);
                Error fieldMsg = null;
                if (arg != null) {
                    String fieldMsgKey = arg.getKey();
                    if (fieldMsgKey != null) {
                        fieldMsg = ErrorFactory.createError(fieldMsgKey);
                    }
                }
                addError(va, errors, field, fieldMsg);
                return false;
            }
        } catch (Exception e) {
            addError(va, errors, field, null);
            return false;
        }
    }
    return true;
}

From source file:org.seasar.struts.customizer.ActionCustomizerTest.java

/**
 * @throws Exception/*from   w w w. ja va2 s .  c  o m*/
 */
public void testCreateField() throws Exception {
    Field field = BbbAction.class.getDeclaredField("hoge");
    Required r = field.getAnnotation(Required.class);
    Map<String, Object> props = AnnotationUtil.getProperties(r);
    org.apache.commons.validator.Field f = customizer.createField("hoge", "required", props,
            validatorResources);
    assertEquals("hoge", f.getProperty());
    assertEquals("required", f.getDepends());
    org.apache.commons.validator.Msg m = f.getMessage("required");
    assertNotNull(m);
    assertEquals("errors.required", m.getKey());
    assertEquals("required", m.getName());
    assertTrue(m.isResource());
    assertNull(m.getBundle());
    org.apache.commons.validator.Arg a = f.getArg("required", 0);
    assertNotNull(a);
    assertEquals("labels.hoge", a.getKey());
    assertNull(a.getName());
    assertTrue(a.isResource());
    assertNull(a.getBundle());
}

From source file:org.springmodules.commons.validator.MessageUtils.java

/**
 * Get the message associated with the argument. If the resource flag is set
 * to false, use the text specified in the argument key directly. Otherwise,
 * create a MessageSourceResolvable with the argument key as its code.
 *///from www  .ja  v  a2  s  .  c o  m
public static Object getMessage(Arg arg) {
    if (arg.isResource()) {
        return createMessage(arg.getKey());
    } else {
        return arg.getKey();
    }
}

From source file:org.springmodules.validation.commons.MessageUtils.java

/**
 * Get the message associated with the argument. If the resource flag is set
 * to false, use the text specified in the argument key directly. Otherwise,
 * create a MessageSourceResolvable with the argument key as its code.
 *//*from  w  ww . j  av a2 s  . com*/
public static Object getMessage(Arg arg) {
    if (arg.isResource()) {
        return MessageUtils.createMessage(arg.getKey());
    } else {
        return arg.getKey();
    }
}