Example usage for org.apache.commons.validator Form addField

List of usage examples for org.apache.commons.validator Form addField

Introduction

In this page you can find the example usage for org.apache.commons.validator Form addField.

Prototype

public void addField(Field f) 

Source Link

Document

Add a Field to the Form.

Usage

From source file:org.agnitas.service.impl.FieldsFactory.java

public void createRulesForCustomFields(CSVColumnState[] columns, Form form,
        ImportRecipientsDao importRecipientsDao, ImportProfile importProfile) {
    for (CSVColumnState column : columns) {
        if (!column.getImportedColumn()) {
            continue;
        }/*from w  ww .j  ava 2 s. co  m*/

        final String colName = column.getColName();
        Map<String, Object> columnInfo = importRecipientsDao
                .getColumnInfoByColumnName(importProfile.getCompanyId(), colName).get(colName);
        final String typeOfCustomColumn = (String) columnInfo.get(ImportRecipientsDao.TYPE);

        final Field field = new Field();
        field.setProperty(colName);
        mTypeColums.put(colName, typeOfCustomColumn);
        if ("email".equals(colName)) {
            column.setType(CSVColumnState.TYPE_CHAR);
            field.setDepends("mandatory,checkRange,email");
            field.addVar("maxLength", "100", null);
        } else if ("gender".equals(colName)) {
            column.setType(CSVColumnState.TYPE_NUMERIC);
            field.setDepends("mandatory,gender");
        } else if ("mailtype".equals(colName)) {
            column.setType(CSVColumnState.TYPE_NUMERIC);
            field.setDepends("mandatory,mailType");
        } else if ("firstname".equals(colName)) {
            column.setType(CSVColumnState.TYPE_CHAR);
            field.setDepends("mandatory,checkRange");
            field.addVar("maxLength", "100", null);
        } else if ("lastname".equals(colName)) {
            column.setType(CSVColumnState.TYPE_CHAR);
            field.setDepends("mandatory,checkRange");
            field.addVar("maxLength", "100", null);
        } else if ("title".equals(colName)) {
            column.setType(CSVColumnState.TYPE_CHAR);
            field.setDepends("mandatory,checkRange");
            field.addVar("maxLength", "100", null);
        } else if (typeOfCustomColumn.equals(DataType.INTEGER)) {
            field.setDepends("mandatory,int");
            markFieldAsCustom(field);
            column.setType(CSVColumnState.TYPE_NUMERIC);
        } else if (typeOfCustomColumn.equals(DataType.DOUBLE)) {
            field.setDepends("mandatory,validateDouble");
            markFieldAsCustom(field);
            column.setType(CSVColumnState.TYPE_NUMERIC);
        } else if (typeOfCustomColumn.equals(DataType.CHAR)) {
            field.setDepends("mandatory,checkRange");
            field.addVar("maxLength", "1", null);
            markFieldAsCustom(field);
            column.setType(CSVColumnState.TYPE_CHAR);
        } else if (typeOfCustomColumn.equals(DataType.VARCHAR)) {
            field.setDepends("mandatory,checkRange");
            final Integer maxLength = (Integer) columnInfo.get("length");
            field.addVar("maxLength", String.valueOf(maxLength), null);
            markFieldAsCustom(field);
            column.setType(CSVColumnState.TYPE_CHAR);
        } else if (typeOfCustomColumn.equals(DataType.DATE)) {
            field.setDepends("mandatory,date");
            markFieldAsCustom(field);
            column.setType(CSVColumnState.TYPE_DATE);
        }

        form.addField(field);
    }
}

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

/**
 * ????/*from   w  w  w .  java2  s .  c  o m*/
 * 
 * 
 * @param propertyName
 *            ??
 * @param validatorName
 *            ???
 * @param props
 *            ??
 * @param validatorResources
 *            
 * @param forms
 *            ??????
 */
protected void registerValidator(String propertyName, String validatorName, Map<String, Object> props,
        S2ValidatorResources validatorResources, Map<String, Form> forms) {
    org.apache.commons.validator.Field field = createField(propertyName, validatorName, props,
            validatorResources);
    for (Iterator<String> i = forms.keySet().iterator(); i.hasNext();) {
        String methodName = i.next();
        if (!isTarget(methodName, (String) props.get("target"))) {
            continue;
        }
        Form form = forms.get(methodName);
        form.addField(field);
    }
}

From source file:org.seasar.struts.lessconfig.factory.AbstractValidatorAnnotationHandler.java

protected void registerField(Form form, Field field, BeanDesc beanDesc, PropertyDesc propDesc) {
    String depends = getDepends(beanDesc, propDesc);
    if (depends == null) {
        if (isNestedValidate(propDesc)) {
            Field nestedField = createField(field, propDesc, "");
            Class nestedClass = propDesc.getPropertyType();
            if (nestedClass.isArray()) {
                nestedClass = nestedClass.getComponentType();
            }/*ww w .j  av  a  2 s .com*/
            BeanDesc nestedBeanDesc = BeanDescFactory.getBeanDesc(nestedClass);
            registerFields(form, nestedField, nestedBeanDesc);
        }
        return;
    }

    Field newField = createField(field, propDesc, depends);
    registerMessage(newField, beanDesc, propDesc);

    if (hasArgsAnnotation(beanDesc, propDesc)) {
        registerArgs(newField, beanDesc, propDesc);
    } else if (hasArgAnnotation(beanDesc, propDesc)) {
        registerArg(newField, beanDesc, propDesc);
    } else {
        registerDefaultArgs(newField, propDesc);
    }

    registerConfig(newField, beanDesc, propDesc);

    form.addField(newField);
}