Package com.vaadin.data

Examples of com.vaadin.data.Validator


        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


                w.showNotification("TextField is " + (tf.isValid() ? "" : "in")
                        + "valid, with error: " + tf.getErrorMessage(),
                        Notification.TYPE_WARNING_MESSAGE);
            }
        });
        tf.addValidator(new Validator() {

            @Override
            public void validate(Object value) throws InvalidValueException {
                if (value == null || value.toString().length() <= 3) {
                    throw new InvalidValueException(
View Full Code Here

                    TextField tf = (TextField) f;
                    tf.setWidth("100%");
                }
                if (propertyId.equals("kilometers")) {
                    f.setWidth("4em");
                    f.addValidator(new Validator() {
                        @Override
                        public void validate(Object value)
                                throws InvalidValueException {
                            // FIXME this does not follow the standard pattern
                            // for validators and has side effects!
View Full Code Here

        form.setValidationVisible(true);
        form.setCaption("This is a form");
        form.setDescription("How do you do?");
        final TextField field1 = new TextField("Write here");
        field1.setImmediate(true);
        field1.addValidator(new Validator() {

            @Override
            public void validate(Object value) throws InvalidValueException {
                if (!isValid(value)) {
                    throw new InvalidValueException("FAIL!");
View Full Code Here

    public void init() {

        final LegacyWindow main = new LegacyWindow("#1811");
        setMainWindow(main);

        Validator strLenValidator = new StringLengthValidator(
                "String must be at least 3 chars long and non-null", 3, -1,
                false);

        TextField tf1 = new TextField(
                "Text field with default settings (required=false)");
View Full Code Here

            // should fail
        }
    }

    public void testRemoveValidator() {
        Validator validator1 = new StringLengthValidator(
                "Length not between 1 and 3", 1, 3, false);
        Validator validator2 = new StringLengthValidator(
                "Length not between 2 and 4", 2, 4, false);

        field.addValidator(validator1);
        field.addValidator(validator2);
        field.removeValidator(validator1);
View Full Code Here

        // succeeds
        field.setValue("abcd");
    }

    public void testRemoveAllValidators() {
        Validator validator1 = new StringLengthValidator(
                "Length not between 1 and 3", 1, 3, false);
        Validator validator2 = new StringLengthValidator(
                "Length not between 2 and 4", 2, 4, false);

        field.addValidator(validator1);
        field.addValidator(validator2);
        field.removeAllValidators();
View Full Code Here

        // tf2.setImmediate(true);
        // addComponent(tf2);

        Date date = new Date(2011 - 1900, 9 - 1, 1);

        Validator dateValidator = new AbstractValidator<Date>(
                "Day of month must be an even number") {

            @Override
            protected boolean isValidValue(Date value) {
                if (value == null) {
View Full Code Here

        // Postal code that must be 5 digits (10000-99999).
        tf = new TextField("Postal Code");
        tf.setColumns(5);

        // Create the validator - this would be even easier with RegexpValidator
        Validator postalCodeValidator = new AbstractStringValidator(
                "Postal code must be a number 10000-99999.") {
            @Override
            protected boolean isValidValue(String value) {
                return value.matches("[1-9][0-9]{4}");
            }
View Full Code Here

    form.getField("id").setRequired(true);
    form.getField("id").setRequiredError(i18nManager.getMessage(Messages.GROUP_ID_REQUIRED));
    form.getField("id").focus();
   
    // Set id field to be unique
    form.getField("id").addValidator(new Validator() {
      public void validate(Object value) throws InvalidValueException {
        if (!isValid(value)) {
          throw new InvalidValueException(i18nManager.getMessage(Messages.GROUP_ID_UNIQUE));
        }
      }
View Full Code Here

TOP

Related Classes of com.vaadin.data.Validator

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.