Example usage for org.apache.commons.validator Field setDepends

List of usage examples for org.apache.commons.validator Field setDepends

Introduction

In this page you can find the example usage for org.apache.commons.validator Field setDepends.

Prototype

public void setDepends(String depends) 

Source Link

Document

Sets the validation rules for this field as a comma separated list.

Usage

From source file:com.sapienter.jbilling.client.payment.PaymentCrudAction.java

private void validateCreditCard() {
    // set up for cc validation, 
    // (meant for use within Validator framework)

    // from validator.xml
    Arg arg = new Arg();
    arg.setKey("all.prompt.creditCard");
    arg.setPosition(0);/*from  ww  w .  j  av a 2s  .co  m*/
    Field field = new Field();
    field.addArg(arg);
    field.setProperty(FIELD_CC_NUMBER);
    field.setDepends("creditCard");

    // from validator-rules.xml
    ValidatorAction va = new ValidatorAction();
    va.setName("creditCard");
    va.setClassname("org.apache.struts.validator.FieldChecks");
    va.setMethod("validateCreditCard");
    va.setMethodParams("java.lang.Object, " + "org.apache.commons.validator.ValidatorAction, "
            + "org.apache.commons.validator.Field, " + "org.apache.struts.action.ActionErrors, "
            + "javax.servlet.http.HttpServletRequest");
    va.setDepends("");
    va.setMsg("errors.creditcard");

    // do cc number validation
    LOG.debug("doing credit card number validation");
    FieldChecks.validateCreditCard(myForm, va, field, errors, request);
}

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  www. j a va2s .  c  o  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.lessconfig.factory.AbstractValidatorAnnotationHandler.java

protected Field createField(Field field, PropertyDesc propDesc, String depends) {
    Field newField = new Field();
    newField.setDepends(depends);

    String property = getFieldProperty(field, propDesc);
    if (propDesc.getPropertyType().isArray()) {
        newField.setProperty("");
        newField.setIndexedListProperty(property);
    } else {/*  w  w  w  .  j  a  v a2 s . c  om*/
        newField.setProperty(property);
        newField.setIndexedListProperty(field.getIndexedListProperty());
    }

    return newField;
}