Search in sources :

Example 1 with InvalidValueException

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;
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with InvalidValueException

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);
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) Group(org.activiti.engine.identity.Group)

Example 3 with InvalidValueException

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);
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) User(org.activiti.engine.identity.User)

Example 4 with InvalidValueException

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)));
}
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 5 with InvalidValueException

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);
}
Also used : InlineDateField(com.vaadin.ui.InlineDateField) Calendar(java.util.Calendar) Label(com.vaadin.ui.Label) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) Button(com.vaadin.ui.Button) TextField(com.vaadin.ui.TextField) VerticalLayout(com.vaadin.ui.VerticalLayout) Property(com.vaadin.data.Property)

Aggregations

InvalidValueException (com.vaadin.data.Validator.InvalidValueException)17 TextField (com.vaadin.ui.TextField)6 Date (java.util.Date)5 Button (com.vaadin.ui.Button)4 Property (com.vaadin.data.Property)3 Validator (com.vaadin.data.Validator)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Label (com.vaadin.ui.Label)3 NativeButton (com.vaadin.ui.NativeButton)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 StringLengthValidator (com.vaadin.data.validator.StringLengthValidator)2 ErrorMessage (com.vaadin.server.ErrorMessage)2 ComboBox (com.vaadin.ui.ComboBox)2 InlineDateField (com.vaadin.ui.InlineDateField)2 PasswordField (com.vaadin.ui.PasswordField)2 ParseException (java.text.ParseException)2 CrudEventType (au.com.vaadinutils.crud.events.CrudEventType)1 ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)1