com.vaadin.server.UserError Java Examples

The following examples show how to use com.vaadin.server.UserError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumericQuestion.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
public boolean isValid(TextField field, String newValue) {
    boolean valid = true;

    if (StringUtils.isBlank(newValue)) {
        if (field.isRequired()) {
            valid = false;
        }
    } else {
        for (Validator v : field.getValidators()) {
            try {
                v.validate(newValue);
            } catch (InvalidValueException e) {
                valid = false;
                logger.warn(e.getMessage());
                answerField.setComponentError(new UserError(e.getMessage()));
            }
        }
    }
    if (valid) {
        answerField.setComponentError(null);
    }
    return valid;
}
 
Example #2
Source File: UploadFileHandler.java    From viritin with Apache License 2.0 6 votes vote down vote up
/**
 * By default just spans a new raw thread to get the input. For strict Java
 * EE fellows, this might not suite, so override and use executor service.
 *
 * @param in the input stream where file content can be handled
 * @param filename the file name on the senders machine
 * @param mimeType the mimeType interpreted from the file name
 */
protected void writeResponce(final PipedInputStream in, String filename, String mimeType) {
    new Thread() {
        @Override
        public void run() {
            try {
                fileHandler.handleFile(in, filename, mimeType);
                in.close();
            } catch (Exception e) {
                getUI().access(() -> {
                    setComponentError(new UserError("Handling file failed"));
                    throw new RuntimeException(e);
                });
            }
        }
    }.start();
}
 
Example #3
Source File: UserErrorProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void processError(Object control, FieldError error) {
	if (control instanceof AbstractField) {
		AbstractField<?> f = (AbstractField<?>) control;
		f.setComponentError(new UserError(StaticMessageSource.getMessage(error)));
		fieldSet.add(f);
	}
}
 
Example #4
Source File: WebDateField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void setValidationError(String errorMessage) {
    if (errorMessage == null) {
        dateField.setComponentError(null);
        timeField.setComponentError(null);
    } else {
        UserError userError = new UserError(errorMessage);
        dateField.setComponentError(userError);
        timeField.setComponentError(userError);
    }
}
 
Example #5
Source File: WebAbstractComponent.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected boolean hasValidationError() {
    if (getComposition() instanceof AbstractComponent) {
        AbstractComponent composition = (AbstractComponent) getComposition();
        return composition.getComponentError() instanceof UserError;
    }
    return false;
}
 
Example #6
Source File: WebAbstractComponent.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setValidationError(String errorMessage) {
    if (getComposition() instanceof AbstractComponent) {
        AbstractComponent composition = (AbstractComponent) getComposition();
        if (errorMessage == null) {
            composition.setComponentError(null);
        } else {
            composition.setComponentError(new UserError(errorMessage));
        }
    }
}
 
Example #7
Source File: WebResizableTextArea.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected CubaTextArea createComponent() {
    return new CubaTextArea() {
        @Override
        public void setComponentError(ErrorMessage componentError) {
            if (componentError instanceof UserError) {
                super.setComponentError(componentError);
            } else {
                wrapper.setComponentError(componentError);
            }
        }
    };
}
 
Example #8
Source File: SignUpViewImpl.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 5 votes vote down vote up
@Override
public void setErrorMessage(String message) {
	username.setComponentError(new UserError(message));
	username.setValidationVisible(true);
	password.setValidationVisible(true);
	firstName.setValidationVisible(true);
	lastName.setValidationVisible(true);
	
}
 
Example #9
Source File: ClearableTextFieldUsageV7.java    From viritin with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTestComponent() {

    ClearableTextField ctf = new ClearableTextField();
    ctf.setCaption("CTF caption");
    ctf.setInputPrompt("Enter text");
    ctf.setValue("Some Text");
    
    ctf.setImmediate(true);

    ctf.addValueChangeListener(e -> {
        Notification.show("Value: " + ctf.getValue());
    });

    MButton b = new MButton("Toggle required", e -> {
        ctf.setRequired(!ctf.isRequired());
    });
    MButton b2 = new MButton("Toggle error", e -> {
        if (ctf.getComponentError() == null) {
            ctf.setComponentError(new UserError("Must be filled"));
        } else {
            ctf.setComponentError(null);
        }
    });

    MButton b3 = new MButton("Toggle readonly", e -> {
        ctf.setReadOnly(!ctf.isReadOnly());
    });

    MButton b4 = new MButton("Toggle enabled", e -> {
        ctf.setEnabled(!ctf.isEnabled());
    });

    return new MPanel()
            .withCaption("ClearableTextField")
            .withDescription("Click the X to clear…")
            .withFullWidth()
            .withFullHeight()
            .withContent(new MVerticalLayout(ctf, b, b2, b3, b4));
}
 
Example #10
Source File: ClearableTextFieldUsage.java    From viritin with Apache License 2.0 5 votes vote down vote up
@Override
    public Component getTestComponent() {

        ClearableTextField ctf = new ClearableTextField();
        ctf.setCaption("CTF caption");
        ctf.setPlaceholder("Enter text");
        ctf.setValue("Some Text");
        

        ctf.addValueChangeListener(e -> {
            Notification.show("Value: " + ctf.getValue());
        });

        // TODO figure out how this works in V8
//        MButton b = new MButton("Toggle required", e -> {
//            ctf.setRequired(!ctf.isRequired());
//        });
        MButton b2 = new MButton("Toggle error", e -> {
            if (ctf.getComponentError() == null) {
                ctf.setComponentError(new UserError("Must be filled"));
            } else {
                ctf.setComponentError(null);
            }
        });

        MButton b3 = new MButton("Toggle readonly", e -> {
            ctf.setReadOnly(!ctf.isReadOnly());
        });

        MButton b4 = new MButton("Toggle enabled", e -> {
            ctf.setEnabled(!ctf.isEnabled());
        });

        return new MPanel()
                .withCaption("ClearableTextField")
                .withDescription("Click the X to clear…")
                .withFullWidth()
                .withFullHeight()
                .withContent(new MVerticalLayout(ctf, /* b,*/ b2, b3, b4));
    }
 
Example #11
Source File: LogIn.java    From jesterj with Apache License 2.0 4 votes vote down vote up
public LogIn() {

  loginLayout.setWidth("100%");
  loginLayout.setHeight("300px");
  loginForm.setSpacing(true);
  loginLabel.setImmediate(true);
  userNameTextField.setRequired(true);
  passwordField.setRequired(true);
  loginSubmit.addClickListener(new Button.ClickListener() {
    @Override
    public void buttonClick(Button.ClickEvent event) {
      authToken.setUsername(userNameTextField.getValue());
      authToken.setPassword(passwordField.getValue().toCharArray());
      try {
        Subject currentUser = SecurityUtils.getSubject();
        currentUser.login(authToken);
        if (currentUser.isAuthenticated()) {
          User user = currentUser.getPrincipals().oneByType(User.class);
          loginLabel.setValue("Hello " + user.getDisplayName());
        }
      } catch (UnknownAccountException uae) {
        userNameTextField.setComponentError(new UserError("Unknown User"));
        loginLabel.setValue("That user does not exist");
      } catch (IncorrectCredentialsException ice) {
        loginLabel.setValue("Invalid password");
        passwordField.setComponentError(new UserError("Invalid Password"));
      } catch (LockedAccountException lae) {
        loginLabel.setValue("Account is locked. Contact your System Administrator");
        loginLabel.setComponentError(new UserError("Account locked"));
      } catch (ExcessiveAttemptsException eae) {
        loginLabel.setValue("Too many login failures.");
        loginLabel.setComponentError(new UserError("Failures Exceeded"));
      } catch (Exception e) {
        e.printStackTrace();
        loginLabel.setValue("Internal Error:" + e.getMessage());
      }
    }

  });
  loginForm.addComponent(loginLabel);
  loginForm.addComponent(userNameTextField);
  loginForm.addComponent(passwordField);
  loginForm.addComponent(loginSubmit);
  loginLayout.addComponent(loginForm, 1, 1);
  }
 
Example #12
Source File: MBeanFieldGroup.java    From viritin with Apache License 2.0 4 votes vote down vote up
protected boolean jsr303ValidateBean(T bean) {
    try {
        if (javaxBeanValidator == null) {
            javaxBeanValidator = getJavaxBeanValidatorFactory().getValidator();
        }
    } catch (Throwable t) {
        // This may happen without JSR303 validation framework
        Logger.getLogger(getClass().getName()).fine(
            "JSR303 validation failed");
        return true;
    }

    boolean containsAtLeastOneBoundComponentWithError = false;
    Set<ConstraintViolation<T>> constraintViolations = new HashSet<>(
        javaxBeanValidator.validate(bean, getValidationGroups()));
    if (constraintViolations.isEmpty()) {
        return true;
    }
    Iterator<ConstraintViolation<T>> iterator = constraintViolations.
        iterator();
    while (iterator.hasNext()) {
        ConstraintViolation<T> constraintViolation = iterator.next();
        Class<? extends Annotation> annotationType = constraintViolation.
            getConstraintDescriptor().getAnnotation().
            annotationType();
        AbstractComponent errortarget = validatorToErrorTarget.get(
            annotationType);
        if (errortarget != null) {
            // user has declared a target component for this constraint
            errortarget.setComponentError(new UserError(
                constraintViolation.getMessage()));
            iterator.remove();
            containsAtLeastOneBoundComponentWithError = true;
        }
        // else leave as "bean level error"
    }
    this.jsr303beanLevelViolations = constraintViolations;
    if (!containsAtLeastOneBoundComponentWithError && isValidateOnlyBoundFields()) {
        return true;
    }
    return false;
}
 
Example #13
Source File: DownloadButton.java    From viritin with Apache License 2.0 4 votes vote down vote up
protected void handleErrorInFileGeneration(Exception e) {
    setComponentError(new UserError(e.getMessage()));
    fireComponentErrorEvent();
    throw new RuntimeException(e);
}
 
Example #14
Source File: WebV8AbstractField.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected ErrorMessage getErrorMessage() {
    return (isEditableWithParent() && isRequired() && isEmpty())
            ? new UserError(getRequiredMessage())
            : null;
}
 
Example #15
Source File: DefineGroupsLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private void setError(final String error) {
    targetPercentage.setComponentError(new UserError(error));
}
 
Example #16
Source File: WebDateField.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean hasValidationError() {
    return dateField.getComponentError() instanceof UserError;
}
 
Example #17
Source File: WebDateField.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected ErrorMessage getErrorMessage() {
    return (isEditableWithParent() && isRequired() && isEmpty())
            ? new UserError(getRequiredMessage())
            : null;
}