use of com.vaadin.flow.data.binder.BeanValidationBinder in project karnak by OsiriX-Foundation.
the class TextFieldsBindSwitchingAlbum method buildBinder.
private Binder<KheopsAlbumsEntity> buildBinder() {
Binder<KheopsAlbumsEntity> b = new BeanValidationBinder<>(KheopsAlbumsEntity.class);
b.forField(textAuthorizationDestination).withValidator(StringUtils::isNotBlank, "Token destination is mandatory").withValidator(value -> {
if (!textUrlAPI.getValue().isBlank()) {
return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_DESTINATION);
}
return true;
}, "Token can't be validate, minimum permissions: [write]").bind(KheopsAlbumsEntity::getAuthorizationDestination, KheopsAlbumsEntity::setAuthorizationDestination);
b.forField(textAuthorizationSource).withValidator(StringUtils::isNotBlank, "Token source is mandatory").withValidator(value -> {
if (!textUrlAPI.getValue().isBlank()) {
return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_SOURCE);
}
return true;
}, "Token can't be validate, minimum permissions: [read, send]").bind(KheopsAlbumsEntity::getAuthorizationSource, KheopsAlbumsEntity::setAuthorizationSource);
b.forField(textUrlAPI).withValidator(StringUtils::isNotBlank, "Url API is mandatory").bind(KheopsAlbumsEntity::getUrlAPI, KheopsAlbumsEntity::setUrlAPI);
b.forField(textCondition).withValidator(value -> {
if (!textCondition.getValue().equals("")) {
expressionError = ExpressionResult.isValid(textCondition.getValue(), new ExprCondition(), Boolean.class);
textErrorConditionMsg.setText(expressionError.getMsg());
return expressionError.isValid();
}
textErrorConditionMsg.setText("");
return true;
}, "Condition is not valid").bind(KheopsAlbumsEntity::getCondition, KheopsAlbumsEntity::setCondition);
return b;
}
use of com.vaadin.flow.data.binder.BeanValidationBinder in project iesi by metadew.
the class AdminView method createCategoryEditor.
private Component createCategoryEditor(Category category) {
TextField nameField = new TextField();
if (category.getId() < 0) {
nameField.focus();
}
Button deleteButton = new Button(VaadinIcon.MINUS_CIRCLE_O.create(), event -> {
DataService.get().deleteCategory(category.getId());
dataProvider.getItems().remove(category);
dataProvider.refreshAll();
Notification.show("Category Deleted.");
});
deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
BeanValidationBinder<Category> binder = new BeanValidationBinder<>(Category.class);
binder.forField(nameField).bind("name");
binder.setBean(category);
binder.addValueChangeListener(event -> {
if (binder.isValid()) {
DataService.get().updateCategory(category);
deleteButton.setEnabled(true);
newCategoryButton.setEnabled(true);
Notification.show("Category Saved.");
}
});
deleteButton.setEnabled(category.getId() > 0);
HorizontalLayout layout = new HorizontalLayout(nameField, deleteButton);
layout.setFlexGrow(1);
return layout;
}
use of com.vaadin.flow.data.binder.BeanValidationBinder in project bookstore-example by vaadin.
the class AdminView method createCategoryEditor.
private Component createCategoryEditor(Category category) {
final TextField nameField = new TextField();
if (category.getId() < 0) {
nameField.focus();
}
final Button deleteButton = new Button(VaadinIcon.MINUS_CIRCLE_O.create(), event -> {
// Ask for confirmation before deleting stuff
final ConfirmDialog dialog = new ConfirmDialog("Please confirm", "Are you sure you want to delete the category? Books in this category will not be deleted.", "Delete", () -> {
DataService.get().deleteCategory(category.getId());
dataProvider.getItems().remove(category);
dataProvider.refreshAll();
Notification.show("Category Deleted.");
});
dialog.open();
});
deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
final BeanValidationBinder<Category> binder = new BeanValidationBinder<>(Category.class);
binder.forField(nameField).bind("name");
binder.setBean(category);
binder.addValueChangeListener(event -> {
if (binder.isValid()) {
DataService.get().updateCategory(category);
deleteButton.setEnabled(true);
newCategoryButton.setEnabled(true);
Notification.show("Category Saved.");
}
});
deleteButton.setEnabled(category.getId() > 0);
final HorizontalLayout layout = new HorizontalLayout(nameField, deleteButton);
layout.setFlexGrow(1);
return layout;
}
Aggregations