本文整理汇总了Java中com.vaadin.data.BindingValidationStatus类的典型用法代码示例。如果您正苦于以下问题:Java BindingValidationStatus类的具体用法?Java BindingValidationStatus怎么用?Java BindingValidationStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingValidationStatus类属于com.vaadin.data包,在下文中一共展示了BindingValidationStatus类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
protected void validate() {
// Clear all validation errors
propertyToBindingMap.values().stream().forEach(e -> e.clearValidationError());
// Validate and set validation errors
if (getBean() != null) {
constraintViolations = validator.validate(getBean(), groups);
constraintViolations.stream().forEach(e -> handleConstraintViolations(e, f -> f.getMessage()));
} else {
constraintViolations = new HashSet<ConstraintViolation<BEAN>>();
}
List<BindingValidationStatus<?>> binRes =
getBindings().stream().map(e -> e.validate(false)).collect(Collectors.toList());
List<ValidationResult> valRes =
constraintViolations.stream()
.filter(e -> e.getPropertyPath().toString().isEmpty())
.map(e -> ValidationResult.error(e.getMessage()))
.collect(Collectors.toList());
status = new BasicBinderValidationStatus<BEAN>(this, binRes, valRes);
getValidationStatusHandler().statusChange(status);
}
示例2: testValidateBinding
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
@Test
public void testValidateBinding() {
EasyBinding<MyEntity, String, Integer> binding = binder.bind(age, MyEntity::getAge, MyEntity::setAge, "age", new StringLengthConverterValidator("Must be a number", 1, null).chain(new StringToIntegerConverter("Must be a number")));
MyEntity bean = new MyEntity();
binder.setBean(bean);
age.setValue("1");
BindingValidationStatus<String> s = binding.validate();
assertTrue(s.getResult().isPresent());
assertFalse(s.getResult().get().isError());
}
示例3: testValidateBindingValidationError
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
@Test
public void testValidateBindingValidationError() {
EasyBinding<MyEntity, String, Integer> binding = binder.bind(age, MyEntity::getAge, MyEntity::setAge, "age", new StringLengthConverterValidator("Must be a number", 1, null).chain(new StringToIntegerConverter("Must be a number")));
MyEntity bean = new MyEntity();
binder.setBean(bean);
age.setValue("-11");
BindingValidationStatus<String> s = binding.validate();
assertTrue(s.getResult().isPresent());
assertTrue(s.getResult().get().isError());
}
示例4: testValidateBindingConversionError
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
@Test
public void testValidateBindingConversionError() {
EasyBinding<MyEntity, String, Integer> binding = binder.bind(age, MyEntity::getAge, MyEntity::setAge, "age", new StringLengthConverterValidator("Must be a number", 1, null).chain(new StringToIntegerConverter("Must be a number")));
MyEntity bean = new MyEntity();
binder.setBean(bean);
age.setValue("nan");
BindingValidationStatus<String> s = binding.validate();
assertTrue(s.getResult().isPresent());
assertTrue(s.getResult().get().isError());
}
示例5: buildNewUserForm
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
private Component buildNewUserForm() {
NewUserForm newUserForm = new NewUserForm();
User user = new User();
newUserForm.getBinder().readBean(user);
newUserFormSave = new Button();
newUserFormSave.setId("newUserFormSave");
newUserFormSave.addStyleName(ValoTheme.BUTTON_FRIENDLY);
newUserFormSave.addClickListener(event -> {
try {
newUserForm.getBinder().writeBean(user);
Services.getUserService().create(user);
newUserForm.clear();
showLoginForm();
} catch (ValidationException e) {
Messages messages = Messages.getInstance();
String message = messages.getMessage("newUserForm.notif.text") + "\n\n";
message += newUserForm.getBinder().validate().getFieldValidationErrors().stream().map(BindingValidationStatus::getMessage)
.filter(Optional::isPresent).map(Optional::get)
.collect(Collectors.joining("\n"));
showNotification(new Notification(message, Notification.Type.ERROR_MESSAGE));
}
});
newUserFormCancel = new Button();
newUserFormCancel.setId("newUserFormCancel");
newUserFormCancel.addClickListener(event -> {
showLoginForm();
});
HorizontalLayout buttons = new HorizontalLayout();
buttons.setSpacing(true);
buttons.addComponents(newUserFormSave, newUserFormCancel);
newUserForm.addComponents(buttons);
return newUserForm;
}
示例6: createBoundEditor
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ElementEditor createBoundEditor(ET pojo) {
ElementEditor es;
Object o = createEditorInstance(pojo);
BeanValidationBinder<ET> beanBinder = new BeanValidationBinder<ET>((Class<ET>) pojo.getClass());
if (isShowStatusLabel()) {
BinderValidationStatusHandler<ET> defaultHandler = beanBinder.getValidationStatusHandler();
FLabel formStatusLabel = new FLabel().withContentMode(ContentMode.HTML).withStyleName(ValoTheme.LABEL_FAILURE);
statusLayout.addComponent(formStatusLabel);
formStatusLabel.setVisible(false);
beanBinder.setValidationStatusHandler(status -> {
List<BindingValidationStatus<?>> fieldErrors = status.getFieldValidationErrors();
List<ValidationResult> beanErrors = status.getBeanValidationErrors();
// collect all bean level error messages into a single string,
// separating each message with a <br> tag
String errorMessage = fieldErrors.stream()
.map(BindingValidationStatus::getMessage)
.map(Optional::get)
.collect(Collectors.joining("<br>"));
String errorMessage2 = beanErrors.stream().map(ValidationResult::getErrorMessage).collect(Collectors.joining("<br>"));
List<String> errorList = Arrays.asList(errorMessage, errorMessage2);
String errors = errorList.stream().filter(s -> !s.isEmpty()).collect(Collectors.joining("<br>"));
// finally, display all bean level validation errors in a single label
formStatusLabel.setValue(errors);
formStatusLabel.setVisible(!errors.isEmpty());
// Let the default handler show messages for each field
defaultHandler.statusChange(status);
});
}
beanBinder.bindInstanceFields(o);
beanBinder.setBean(pojo);
beanBinder.addStatusChangeListener(scl);
es = new ElementEditor(beanBinder, o);
pojoToEditor.put(pojo, es);
return es;
}
示例7: BasicBinderValidationStatus
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Creates a new binder validation status for the given binder and validation
* results.
*
* @param source
* the source binder
* @param bindingStatuses
* the validation results for the fields
* @param binderStatuses
* the validation results for binder level validation
*/
public BasicBinderValidationStatus(BasicBinder<BEAN> source, List<BindingValidationStatus<?>> bindingStatuses,
List<ValidationResult> binderStatuses) {
Objects.requireNonNull(binderStatuses, "binding statuses cannot be null");
Objects.requireNonNull(binderStatuses, "binder statuses cannot be null");
this.binder = source;
this.bindingStatuses = Collections.unmodifiableList(bindingStatuses);
this.binderStatuses = Collections.unmodifiableList(binderStatuses);
}
示例8: notifyBindingValidationStatusHandlers
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Notifies validation status handlers for bindings that pass given filter. The
* filter should return {@code true} for each {@link BindingValidationStatus}
* that should be delegated to the status handler in the binding.
*
* @see #notifyBindingValidationStatusHandlers()
*
* @param filter
* the filter to select bindings to run status handling for
*/
@SuppressWarnings("unchecked")
public void notifyBindingValidationStatusHandlers(SerializablePredicate<BindingValidationStatus<?>> filter) {
bindingStatuses.stream().filter(filter)
.forEach(s -> ((BasicBinder.EasyBinding<BEAN, ?, ?>) s.getBinding()).getValidationStatusHandler()
.statusChange(s));
}
示例9: createUnresolvedStatus
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Convenience method for creating a unresolved validation status for the given
* binder.
* <p>
* In practice this status means that the values might not be valid, but
* validation errors should be hidden.
*
* @param source
* the source binder
* @return a unresolved validation status
* @param <BEAN>
* the bean type of the binder
*/
public static <BEAN> BasicBinderValidationStatus<BEAN> createUnresolvedStatus(BasicBinder<BEAN> source) {
return new BasicBinderValidationStatus<>(source, source.getBindings().stream()
.map(b -> BindingValidationStatus.createUnresolvedStatus(b)).collect(Collectors.toList()),
Collections.emptyList());
}
示例10: hasErrors
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Gets whether the validation for the binder failed or not.
*
* @return {@code true} if validation failed, {@code false} if validation passed
*/
public boolean hasErrors() {
return binderStatuses.stream().filter(ValidationResult::isError).findAny().isPresent()
|| bindingStatuses.stream().filter(BindingValidationStatus::isError).findAny().isPresent();
}
示例11: getFieldValidationStatuses
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Gets the field level validation statuses.
* <p>
* The field level validators have been added with
* {@link BindingBuilder#withValidator(Validator)}.
*
* @return the field validation statuses
*/
public List<BindingValidationStatus<?>> getFieldValidationStatuses() {
return bindingStatuses;
}
示例12: getFieldValidationErrors
import com.vaadin.data.BindingValidationStatus; //导入依赖的package包/类
/**
* Gets the failed field level validation statuses.
* <p>
* The field level validators have been added with
* {@link BindingBuilder#withValidator(Validator)}.
*
* @return a list of failed field level validation statuses
*/
public List<BindingValidationStatus<?>> getFieldValidationErrors() {
return bindingStatuses.stream().filter(BindingValidationStatus::isError).collect(Collectors.toList());
}