Search in sources :

Example 1 with Validator

use of db.Validator in project common by zenlunatics.

the class ColumnBase method validate.

// --------------------------------------------------------------------------
public String validate(String table, String value, int id, Request request) {
    if (m_is_required && value != null && value.length() == 0)
        return "Required Field: Please enter a value for " + getDisplayName(false);
    if (m_is_unique) {
        NameValuePairs nvp = new NameValuePairs();
        nvp.set(m_name, value);
        boolean different = false;
        if (id != 0) {
            String current_value = request.db.lookupString(m_name, table, id);
            if (current_value == null && value != null && value.length() > 0)
                different = true;
            else
                different = !value.equals(current_value);
        }
        if (id == 0 || different)
            if (request.db.exists(table, nvp.getWhereString(request.db, table)))
                return "There is already a " + getDisplayName(false) + " with value \"" + value + "\". Please enter a different value for " + getDisplayName(false);
    }
    if (m_validators != null)
        for (Validator validator : m_validators) {
            String error = validator.validate(table, value, request);
            if (error != null)
                return error;
        }
    return null;
}
Also used : NameValuePairs(db.NameValuePairs) Validator(db.Validator)

Aggregations

NameValuePairs (db.NameValuePairs)1 Validator (db.Validator)1