use of com.vaadin.data.Validator.InvalidValueException in project Activiti by Activiti.
the class FileAttachmentEditorComponent method getAttachment.
public Attachment getAttachment() throws InvalidValueException {
// Force validation of the fields
form.commit();
// Check if file is uploaded
if (!fileUploaded) {
InvalidValueException ive = new InvalidValueException(i18nManager.getMessage(Messages.RELATED_CONTENT_TYPE_FILE_REQUIRED));
form.setComponentError(ive);
throw ive;
}
if (attachment != null) {
applyValuesToAttachment();
} else {
// Create new attachment based on values
// TODO: use explorerApp to get services
attachment = taskService.createAttachment(mimeType, taskId, processInstanceId, getAttachmentName(), getAttachmentDescription(), new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
}
return attachment;
}
use of com.vaadin.data.Validator.InvalidValueException in project Activiti by Activiti.
the class NewGroupPopupWindow method handleFormSubmit.
protected void handleFormSubmit() {
try {
// create user
// will throw exception in case validation is false
form.commit();
Group group = createGroup();
// close popup and navigate to new group
close();
ExplorerApp.get().getViewManager().showGroupPage(group.getId());
} catch (InvalidValueException e) {
// Do nothing: the Form component will render the errormsgs automatically
setHeight(270, UNITS_PIXELS);
}
}
use of com.vaadin.data.Validator.InvalidValueException in project Activiti by Activiti.
the class NewUserPopupWindow method handleFormSubmit.
protected void handleFormSubmit() {
try {
// create user
// will throw exception in case validation is false
form.commit();
User user = createUser();
// close popup and navigate to fresh user
close();
ExplorerApp.get().getViewManager().showUserPage(user.getId());
} catch (InvalidValueException e) {
// Do nothing: the Form component will render the errormsgs automatically
setHeight(340, UNITS_PIXELS);
}
}
use of com.vaadin.data.Validator.InvalidValueException 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.InvalidValueException in project VaadinUtils by rlsutton1.
the class DateTimePickerInline method buildUI.
@Override
protected void buildUI(String title) {
datePicker = new InlineDateField(title + " Date");
datePicker.setDateFormat("yyyy/MM/dd");
datePicker.setValue(new Date());
displayDate = createTextDateField();
datePicker.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(Property.ValueChangeEvent event) {
final Date date = (Date) event.getProperty().getValue();
displayDate.setValue(dateFormatter.format(date));
}
});
final Label midnightLabel = new Label();
midnightLabel.setContentMode(ContentMode.HTML);
field = new TextField();
field.setWidth("125");
field.setImmediate(true);
displayTime = field;
displayTime.addValidator(timeValidator);
field.addValidator(timeValidator);
field.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
DateTimePickerInline.this.valueChange(event);
@SuppressWarnings("deprecation") int hour = getValue().getHours();
if (hour == 0) {
midnightLabel.setValue("<font color='red'><b>Midnight</b></font>");
} else {
midnightLabel.setValue("");
}
try {
final Date parsedDate = parseDate((String) event.getProperty().getValue());
if (parsedDate != null) {
Calendar parsed = Calendar.getInstance();
parsed.setTime(parsedDate);
dateTime.set(Calendar.HOUR_OF_DAY, parsed.get(Calendar.HOUR_OF_DAY));
dateTime.set(Calendar.MINUTE, parsed.get(Calendar.MINUTE));
isSet = true;
setNewValue();
}
} catch (InvalidValueException e) {
logger.info(e);
// the validator will handle this
}
}
});
field.setCaption(null);
datePicker.setCaption(null);
VerticalLayout vl = new VerticalLayout();
HorizontalLayout dateLayout = new HorizontalLayout();
dateLayout.setWidth("210");
Button changeYearButton = new Button("Year");
changeYearButton.setDescription("Change the year");
changeYearButton.setStyleName(ValoTheme.BUTTON_TINY);
changeYearButton.addClickListener(getChangeYearClickListener());
dateLayout.addComponent(displayDate);
dateLayout.addComponent(changeYearButton);
dateLayout.setComponentAlignment(changeYearButton, Alignment.MIDDLE_RIGHT);
vl.addComponent(datePicker);
HorizontalLayout timeFieldLayout = new HorizontalLayout();
timeFieldLayout.setSpacing(true);
timeFieldLayout.addComponent(field);
timeFieldLayout.addComponent(midnightLabel);
timeFieldLayout.setComponentAlignment(midnightLabel, Alignment.MIDDLE_LEFT);
vl.addComponent(buildInline());
addComponent(vl);
vl.addComponent(timeFieldLayout);
vl.addComponent(dateLayout);
vl.setSpacing(true);
}
Aggregations