类com.vaadin.server.UserError源码实例Demo

下面列出了怎么用com.vaadin.server.UserError的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: viritin   文件: UploadFileHandler.java
/**
 * 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();
}
 
源代码2 项目: gazpachoquest   文件: NumericQuestion.java
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;
}
 
源代码3 项目: cuba   文件: WebDateField.java
@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);
    }
}
 
源代码4 项目: cuba   文件: WebAbstractComponent.java
protected boolean hasValidationError() {
    if (getComposition() instanceof AbstractComponent) {
        AbstractComponent composition = (AbstractComponent) getComposition();
        return composition.getComponentError() instanceof UserError;
    }
    return false;
}
 
源代码5 项目: cuba   文件: WebAbstractComponent.java
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));
        }
    }
}
 
源代码6 项目: cuba   文件: WebResizableTextArea.java
protected CubaTextArea createComponent() {
    return new CubaTextArea() {
        @Override
        public void setComponentError(ErrorMessage componentError) {
            if (componentError instanceof UserError) {
                super.setComponentError(componentError);
            } else {
                wrapper.setComponentError(componentError);
            }
        }
    };
}
 
源代码7 项目: viritin   文件: ClearableTextFieldUsage.java
@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));
    }
 
源代码8 项目: viritin   文件: ClearableTextFieldUsageV7.java
@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));
}
 
@Override
public void setErrorMessage(String message) {
	username.setComponentError(new UserError(message));
	username.setValidationVisible(true);
	password.setValidationVisible(true);
	firstName.setValidationVisible(true);
	lastName.setValidationVisible(true);
	
}
 
源代码10 项目: jdal   文件: UserErrorProcessor.java
/**
 * {@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);
	}
}
 
源代码11 项目: cuba   文件: WebV8AbstractField.java
protected ErrorMessage getErrorMessage() {
    return (isEditableWithParent() && isRequired() && isEmpty())
            ? new UserError(getRequiredMessage())
            : null;
}
 
源代码12 项目: cuba   文件: WebDateField.java
protected ErrorMessage getErrorMessage() {
    return (isEditableWithParent() && isRequired() && isEmpty())
            ? new UserError(getRequiredMessage())
            : null;
}
 
源代码13 项目: cuba   文件: WebDateField.java
@Override
protected boolean hasValidationError() {
    return dateField.getComponentError() instanceof UserError;
}
 
源代码14 项目: hawkbit   文件: DefineGroupsLayout.java
private void setError(final String error) {
    targetPercentage.setComponentError(new UserError(error));
}
 
源代码15 项目: jesterj   文件: LogIn.java
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);
  }
 
源代码16 项目: viritin   文件: DownloadButton.java
protected void handleErrorInFileGeneration(Exception e) {
    setComponentError(new UserError(e.getMessage()));
    fireComponentErrorEvent();
    throw new RuntimeException(e);
}
 
源代码17 项目: viritin   文件: MBeanFieldGroup.java
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;
}