Package com.vaadin.data.validator

Examples of com.vaadin.data.validator.CompositeValidator


        setMainWindow(mainWin);

        final TextField tx = new TextField("Integer");
        mainWin.addComponent(tx);
        tx.setImmediate(true);
        CompositeValidator v = new CompositeValidator();
        v.addValidator(new IntegerValidator("{0} is not a number"));
        v.addValidator(new Validator() {

            private boolean isValid(Object value) {
                try {
                    int i = Integer.parseInt("" + value);
                    if (i < 0) {
                        return false;
                    }
                    return true;
                } catch (NumberFormatException e) {
                    return false;
                }
            }

            @Override
            public void validate(Object value) throws InvalidValueException {
                if (!isValid(value)) {
                    throw new InvalidValueException(value
                            + " is not a non-negative number");
                }
            }
        });
        CompositeValidator v2 = new CompositeValidator(CombinationMode.OR, null);
        v2.addValidator(v);
        v2.addValidator(new Validator() {

            @Override
            public void validate(Object value) throws InvalidValueException {
                if (!"".equals("" + value)) {
                    throw new InvalidValueException("Value is not empty string");
View Full Code Here


        form.addField("i", tf);

        // TODO CompositeValidator
        tf = new TextField(
                "A field, must be a floating point number with 4-5 chars");
        CompositeValidator cv = new CompositeValidator(CombinationMode.AND,
                "The field must contain a floating point number with 4-5 characters");
        cv.addValidator(new StringLengthValidator(
                "String length of '{0}' should be 4-5 characters", 4, 5, false));
        cv.addValidator(new DoubleValidator(
                "{0} must be a floating point number"));
        tf.addValidator(cv);
        tf.setValue("12.34");
        form.addField("j", tf);

        tf = new TextField(
                "A field, must be a floating point number or 4-5 chars");
        cv = new CompositeValidator(CombinationMode.OR,
                "The field must contain a floating point  or with 4-5 characters");
        cv.addValidator(new StringLengthValidator(
                "String length of '{0}' should be 4-5 characters", 4, 5, false));
        cv.addValidator(new DoubleValidator(
                "{0} must be a floating point number"));
        tf.addValidator(cv);
        tf.setValue("12.34g");
        form.addField("jb", tf);
View Full Code Here

TOP

Related Classes of com.vaadin.data.validator.CompositeValidator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.