Search in sources :

Example 1 with Validator

use of javax.faces.validator.Validator in project ART-TIME by Artezio.

the class Column method validate.

/**
 * Process all validators (skip normal UIInput behavior)
 */
@Override
public void validate(FacesContext context) {
    if (context == null) {
        throw new NullPointerException();
    }
    final Validator[] validators = getValidators();
    final Object value = getValue();
    if (!validateRequired(context, value))
        return;
    if (validators == null)
        return;
    for (Validator validator : validators) {
        try {
            validator.validate(context, this, value);
        } catch (ValidatorException ve) {
            // If the validator throws an exception, we're
            // invalid, and we need to add a message
            setValid(false);
            FacesMessage message;
            String validatorMessageString = getValidatorMessage();
            if (null != validatorMessageString) {
                message = new FacesMessage(FacesMessage.SEVERITY_ERROR, validatorMessageString, validatorMessageString);
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
            } else {
                Collection<FacesMessage> messages = ve.getFacesMessages();
                if (null != messages) {
                    message = null;
                    String cid = getClientId(context);
                    for (FacesMessage m : messages) {
                        context.addMessage(cid, m);
                    }
                } else {
                    message = ve.getFacesMessage();
                }
            }
            if (message != null) {
                Sheet sheet = getSheet();
                if (sheet == null)
                    return;
                context.addMessage(getClientId(context), message);
                sheet.getBadUpdates().add(new BadUpdate(sheet.getRowKeyValue(context), sheet.getColumns().indexOf(this), this, value, message.getDetail()));
            }
        }
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) Collection(java.util.Collection) FacesMessage(javax.faces.application.FacesMessage) Validator(javax.faces.validator.Validator)

Aggregations

Collection (java.util.Collection)1 FacesMessage (javax.faces.application.FacesMessage)1 Validator (javax.faces.validator.Validator)1 ValidatorException (javax.faces.validator.ValidatorException)1