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)));
}
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;
}
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);
}
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);
}
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");
}
}
});
}
Aggregations