Search in sources :

Example 1 with Validator

use of com.vaadin.data.Validator in project Activiti by Activiti.

the class NewUserPopupWindow method initInputFields.

protected void initInputFields() {
    // Input fields
    form.addField("id", new TextField(i18nManager.getMessage(Messages.USER_ID)));
    // Set id field to required
    form.getField("id").setRequired(true);
    form.getField("id").setRequiredError(i18nManager.getMessage(Messages.USER_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.USER_ID_UNIQUE));
            }
        }

        public boolean isValid(Object value) {
            if (value != null) {
                return identityService.createUserQuery().userId(value.toString()).singleResult() == null;
            }
            return false;
        }
    });
    // Password is required
    form.addField("password", new PasswordField(i18nManager.getMessage(Messages.USER_PASSWORD)));
    form.getField("password").setRequired(true);
    form.getField("password").setRequiredError(i18nManager.getMessage(Messages.USER_PASSWORD_REQUIRED));
    // Password must be at least 5 characters
    StringLengthValidator passwordLengthValidator = new StringLengthValidator(i18nManager.getMessage(Messages.USER_PASSWORD_MIN_LENGTH, 5), 5, -1, false);
    form.getField("password").addValidator(passwordLengthValidator);
    form.addField("firstName", new TextField(i18nManager.getMessage(Messages.USER_FIRSTNAME)));
    form.addField("lastName", new TextField(i18nManager.getMessage(Messages.USER_LASTNAME)));
    form.addField("email", new TextField(i18nManager.getMessage(Messages.USER_EMAIL)));
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) StringLengthValidator(com.vaadin.data.validator.StringLengthValidator) TextField(com.vaadin.ui.TextField) PasswordField(com.vaadin.ui.PasswordField) StringLengthValidator(com.vaadin.data.validator.StringLengthValidator) Validator(com.vaadin.data.Validator)

Example 2 with Validator

use of com.vaadin.data.Validator in project VaadinUtils by rlsutton1.

the class ReportParameterString method setNotEmpty.

public ReportParameter<?> setNotEmpty() {
    Validator validator = new Validator() {

        /**
         */
        private static final long serialVersionUID = 8942263638713110223L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            logger.info(value);
        }
    };
    field.addValidator(validator);
    return this;
}
Also used : Validator(com.vaadin.data.Validator)

Example 3 with Validator

use of com.vaadin.data.Validator in project Activiti by Activiti.

the class NewGroupPopupWindow method initInputFields.

protected void initInputFields() {
    // Input fields
    form.addField("id", new TextField(i18nManager.getMessage(Messages.GROUP_ID)));
    // Set id field to required
    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));
            }
        }

        public boolean isValid(Object value) {
            if (value != null) {
                return identityService.createGroupQuery().groupId(value.toString()).singleResult() == null;
            }
            return false;
        }
    });
    form.addField("name", new TextField(i18nManager.getMessage(Messages.GROUP_NAME)));
    ComboBox typeComboBox = new ComboBox(i18nManager.getMessage(Messages.GROUP_TYPE), Arrays.asList("assignment", "security-role"));
    typeComboBox.select("assignment");
    form.addField("type", typeComboBox);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) Validator(com.vaadin.data.Validator)

Example 4 with Validator

use of com.vaadin.data.Validator in project opennms by OpenNMS.

the class AttributeNameValidatorTest method testValidate.

@Test
public void testValidate() {
    final String[] OK = new String[] { "com", "comwebserver", "someEntry", "HELLOWORLD", "HellowoRlD", "a", "ab" };
    final String[] FAIL = new String[] { "", ".", ".org", "opennms.", ".serviceopennms.org", "servicename!", "someadditional-entry", "some_Entry", "com.java.op-erating-system", "some.entry.separated.by_.dots.a__.lot.of_.dots", "ab.cd", "a.bc", "ab.c", "service name", "service,name", "service, name", "straße", "schädel", "hühner", "hölle" };
    Validator validator = new AttributeNameValidator();
    NameValidatorTest.validate(validator, OK, true);
    NameValidatorTest.validate(validator, FAIL, false);
}
Also used : Validator(com.vaadin.data.Validator) Test(org.junit.Test)

Example 5 with Validator

use of com.vaadin.data.Validator in project VaadinUtils by rlsutton1.

the class ReportParameterDateTimeRange method createValidators.

void createValidators() {
    startfield.addValidator(new Validator() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            if (value == null) {
                throw new InvalidValueException("Start date is invalid");
            }
            if (endfield.getValue() != null && ((Date) value).after(endfield.getValue())) {
                throw new InvalidValueException("Start date must be before the end date");
            }
        }
    });
    endfield.addValidator(new Validator() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            if (value == null) {
                throw new InvalidValueException("End date is invalid");
            }
            if (startfield.getValue() != null && ((Date) value).before(startfield.getValue())) {
                throw new InvalidValueException("Start date must be before the end date");
            }
        }
    });
}
Also used : Validator(com.vaadin.data.Validator) Date(java.util.Date)

Aggregations

Validator (com.vaadin.data.Validator)6 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)3 TextField (com.vaadin.ui.TextField)3 Date (java.util.Date)2 Property (com.vaadin.data.Property)1 StringLengthValidator (com.vaadin.data.validator.StringLengthValidator)1 ComboBox (com.vaadin.ui.ComboBox)1 PasswordField (com.vaadin.ui.PasswordField)1 ParseException (java.text.ParseException)1 Test (org.junit.Test)1