summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-09-13 11:12:00 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-13 10:13:32 +0000
commitad33cb573e1571167a80e9aaf02cb329c0aa4da8 (patch)
tree07572fa3b9c0944c2b657e748b6a23f3d80a939f
parente8397bf3c96a0be1c3c635f99c1b1dfacd058a89 (diff)
downloadvaadin-framework-ad33cb573e1571167a80e9aaf02cb329c0aa4da8.tar.gz
vaadin-framework-ad33cb573e1571167a80e9aaf02cb329c0aa4da8.zip
Fix inconsistent API naming in Binder and remove unused handler
Mostly based on comments on a previous patch that was merged. Change-Id: I146995853b3318d89061f1d06ab4bbd859168661
-rw-r--r--documentation/datamodel/datamodel-forms.asciidoc11
-rw-r--r--server/src/main/java/com/vaadin/data/BeanBinder.java8
-rw-r--r--server/src/main/java/com/vaadin/data/Binder.java104
-rw-r--r--server/src/main/java/com/vaadin/data/BinderStatusHandler.java45
-rw-r--r--server/src/main/java/com/vaadin/data/BinderValidationStatus.java27
-rw-r--r--server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java9
-rw-r--r--server/src/main/java/com/vaadin/data/Result.java14
-rw-r--r--server/src/main/java/com/vaadin/data/SimpleResult.java6
-rw-r--r--server/src/main/java/com/vaadin/data/ValidationException.java37
-rw-r--r--server/src/main/java/com/vaadin/data/ValidationStatus.java8
-rw-r--r--server/src/main/java/com/vaadin/data/ValidationStatusHandler.java7
-rw-r--r--server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java17
-rw-r--r--server/src/test/java/com/vaadin/data/BinderTest.java64
13 files changed, 154 insertions, 203 deletions
diff --git a/documentation/datamodel/datamodel-forms.asciidoc b/documentation/datamodel/datamodel-forms.asciidoc
index 62d844dee6..3c2dd95bb5 100644
--- a/documentation/datamodel/datamodel-forms.asciidoc
+++ b/documentation/datamodel/datamodel-forms.asciidoc
@@ -150,11 +150,10 @@ binder.forField(nameField)
.withValidator(
name -> name.length() >= 3,
"Full name must contain at least three characters")
- .withStatusChangeHandler(statusChange -> {
- nameStatus.setValue(statusChange.getMessage().orElse(""));
+ .withValidationStatusHandler(status -> {
+ nameStatus.setValue(status.getMessage().orElse(""));
// Only show the label when validation has failed
- boolean error = statusChange.getStatus() == ValidationStatus.ERROR;
- nameStatus.setVisible(error);
+ nameStatus.setVisible(status.isError());
})
.bind(Person::getName, Person::setName);
----
@@ -564,9 +563,9 @@ We can also define our own status handler to provide a custom way of handling st
[source, java]
----
-BinderStatusHandler defaultHandler = binder.getStatusHandler();
+BinderValidationStatusHandler defaultHandler = binder.getValidationStatusHandler();
-binder.setStatusHandler(status -> {
+binder.setValidationStatusHandler(status -> {
// create an error message on failed bean level validations
List<Result<?>> errors = status.getBeanValidationErrors();
String errorMessage = errors.stream().map(Result::getMessage)
diff --git a/server/src/main/java/com/vaadin/data/BeanBinder.java b/server/src/main/java/com/vaadin/data/BeanBinder.java
index cbabdb80cb..dd5790b8b6 100644
--- a/server/src/main/java/com/vaadin/data/BeanBinder.java
+++ b/server/src/main/java/com/vaadin/data/BeanBinder.java
@@ -143,14 +143,14 @@ public class BeanBinder<BEAN> extends Binder<BEAN> {
* the field to use, not null
* @param converter
* the initial converter to use, not null
- * @param statusChangeHandler
+ * @param statusHandler
* the handler to notify of status changes, not null
*/
protected BeanBindingImpl(BeanBinder<BEAN> binder,
HasValue<FIELDVALUE> field,
Converter<FIELDVALUE, TARGET> converter,
- ValidationStatusHandler statusChangeHandler) {
- super(binder, field, converter, statusChangeHandler);
+ ValidationStatusHandler statusHandler) {
+ super(binder, field, converter, statusHandler);
}
@Override
@@ -275,7 +275,7 @@ public class BeanBinder<BEAN> extends Binder<BEAN> {
public <FIELDVALUE> BeanBinding<BEAN, FIELDVALUE, FIELDVALUE> forField(
HasValue<FIELDVALUE> field) {
return createBinding(field, Converter.identity(),
- this::handleValidationStatusChange);
+ this::handleValidationStatus);
}
/**
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java
index f58c69bb7b..ba579148b9 100644
--- a/server/src/main/java/com/vaadin/data/Binder.java
+++ b/server/src/main/java/com/vaadin/data/Binder.java
@@ -300,15 +300,15 @@ public class Binder<BEAN> implements Serializable {
* default behavior).
* <p>
* This is just a shorthand for
- * {@link #withStatusHandler(StatusChangeHandler)} method where the
- * handler instance hides the {@code label} if there is no error and
- * shows it with validation error message if validation fails. It means
- * that it cannot be called after
- * {@link #withStatusHandler(StatusChangeHandler)} method call or
- * {@link #withStatusHandler(StatusChangeHandler)} after this method
- * call.
+ * {@link #withValidationStatusHandler(ValidationStatusHandler)} method
+ * where the handler instance hides the {@code label} if there is no
+ * error and shows it with validation error message if validation fails.
+ * It means that it cannot be called after
+ * {@link #withValidationStatusHandler(ValidationStatusHandler)} method
+ * call or {@link #withValidationStatusHandler(ValidationStatusHandler)}
+ * after this method call.
*
- * @see #withStatusHandler(StatusChangeHandler)
+ * @see #withValidationStatusHandler(ValidationStatusHandler)
* @see AbstractComponent#setComponentError(ErrorMessage)
* @param label
* label to show validation status for the field
@@ -316,7 +316,7 @@ public class Binder<BEAN> implements Serializable {
*/
public default Binding<BEAN, FIELDVALUE, TARGET> withStatusLabel(
Label label) {
- return withStatusHandler(status -> {
+ return withValidationStatusHandler(status -> {
label.setValue(status.getMessage().orElse(""));
// Only show the label when validation has failed
label.setVisible(status.isError());
@@ -324,7 +324,7 @@ public class Binder<BEAN> implements Serializable {
}
/**
- * Sets a {@link StatusChangeHandler} to track validation status
+ * Sets a {@link ValidationStatusHandler} to track validation status
* changes.
* <p>
* The validation state of each field is updated whenever the user
@@ -352,7 +352,7 @@ public class Binder<BEAN> implements Serializable {
* status change handler
* @return this binding, for chaining
*/
- public Binding<BEAN, FIELDVALUE, TARGET> withStatusHandler(
+ public Binding<BEAN, FIELDVALUE, TARGET> withValidationStatusHandler(
ValidationStatusHandler handler);
/**
@@ -408,16 +408,16 @@ public class Binder<BEAN> implements Serializable {
* the field to bind, not null
* @param converterValidatorChain
* the converter/validator chain to use, not null
- * @param statusChangeHandler
+ * @param statusHandler
* the handler to track validation status, not null
*/
protected BindingImpl(Binder<BEAN> binder, HasValue<FIELDVALUE> field,
Converter<FIELDVALUE, TARGET> converterValidatorChain,
- ValidationStatusHandler statusChangeHandler) {
+ ValidationStatusHandler statusHandler) {
this.field = field;
this.binder = binder;
this.converterValidatorChain = converterValidatorChain;
- this.statusHandler = statusChangeHandler;
+ this.statusHandler = statusHandler;
}
@Override
@@ -454,13 +454,14 @@ public class Binder<BEAN> implements Serializable {
}
@Override
- public Binding<BEAN, FIELDVALUE, TARGET> withStatusHandler(
+ public Binding<BEAN, FIELDVALUE, TARGET> withValidationStatusHandler(
ValidationStatusHandler handler) {
checkUnbound();
Objects.requireNonNull(handler, "handler cannot be null");
if (isStatusHandlerChanged) {
throw new IllegalStateException(
- "A StatusChangeHandler has already been set");
+ "A " + ValidationStatusHandler.class.getSimpleName()
+ + " has already been set");
}
isStatusHandlerChanged = true;
statusHandler = handler;
@@ -504,8 +505,8 @@ public class Binder<BEAN> implements Serializable {
@Override
public ValidationStatus<TARGET> validate() {
- ValidationStatus<TARGET> status = getTargetValue();
- getBinder().getStatusHandler()
+ ValidationStatus<TARGET> status = doValidation();
+ getBinder().getValidationStatusHandler()
.accept(new BinderValidationStatus<>(getBinder(),
Arrays.asList(status), Collections.emptyList()));
return status;
@@ -515,10 +516,9 @@ public class Binder<BEAN> implements Serializable {
* Returns the field value run through all converters and validators,
* but doesn't pass the {@link ValidationStatus} to any status handler.
*
- * @return a result containing the validated and converted value or
- * describing an error
+ * @return the validation status
*/
- private ValidationStatus<TARGET> getTargetValue() {
+ private ValidationStatus<TARGET> doValidation() {
FIELDVALUE fieldValue = field.getValue();
Result<TARGET> dataValue = converterValidatorChain.convertToModel(
fieldValue, ((AbstractComponent) field).getLocale());
@@ -560,13 +560,13 @@ public class Binder<BEAN> implements Serializable {
bean);
List<Result<?>> binderValidationResults;
// if all field level validations pass, run bean level validation
- if (!getBinder().bindings.stream().map(BindingImpl::getTargetValue)
+ if (!getBinder().bindings.stream().map(BindingImpl::doValidation)
.anyMatch(ValidationStatus::isError)) {
binderValidationResults = binder.validateItem(bean);
} else {
binderValidationResults = Collections.emptyList();
}
- binder.getStatusHandler()
+ binder.getValidationStatusHandler()
.accept(new BinderValidationStatus<>(binder,
Arrays.asList(fieldValidationStatus),
binderValidationResults));
@@ -582,7 +582,7 @@ public class Binder<BEAN> implements Serializable {
private ValidationStatus<TARGET> storeFieldValue(BEAN bean) {
assert bean != null;
- ValidationStatus<TARGET> validationStatus = getTargetValue();
+ ValidationStatus<TARGET> validationStatus = doValidation();
if (setter != null) {
validationStatus.getResult().ifPresent(result -> result
.ifOk(value -> setter.accept(bean, value)));
@@ -594,7 +594,7 @@ public class Binder<BEAN> implements Serializable {
setter.accept(bean, value);
}
- private void notifyStatusChangeHandler(ValidationStatus<?> status) {
+ private void notifyStatusHandler(ValidationStatus<?> status) {
statusHandler.accept(status);
}
}
@@ -647,7 +647,7 @@ public class Binder<BEAN> implements Serializable {
private Label statusLabel;
- private BinderStatusHandler statusHandler;
+ private BinderValidationStatusHandler statusHandler;
private boolean hasChanges = false;
@@ -682,7 +682,7 @@ public class Binder<BEAN> implements Serializable {
getStatusLabel().ifPresent(label -> label.setValue(""));
return createBinding(field, Converter.identity(),
- this::handleValidationStatusChange);
+ this::handleValidationStatus);
}
/**
@@ -771,7 +771,7 @@ public class Binder<BEAN> implements Serializable {
bean = null;
bindings.forEach(BindingImpl::unbind);
}
- getStatusHandler()
+ getValidationStatusHandler()
.accept(BinderValidationStatus.createUnresolvedStatus(this));
}
@@ -795,7 +795,7 @@ public class Binder<BEAN> implements Serializable {
setHasChanges(false);
bindings.forEach(binding -> binding.setFieldValue(bean));
- getStatusHandler()
+ getValidationStatusHandler()
.accept(BinderValidationStatus.createUnresolvedStatus(this));
}
@@ -937,7 +937,7 @@ public class Binder<BEAN> implements Serializable {
validationStatus = new BinderValidationStatus<>(this,
bindingStatuses, validateItem(bean));
}
- getStatusHandler().accept(validationStatus);
+ getValidationStatusHandler().accept(validationStatus);
return validationStatus;
}
@@ -954,7 +954,7 @@ public class Binder<BEAN> implements Serializable {
private List<ValidationStatus<?>> validateBindings() {
List<ValidationStatus<?>> results = new ArrayList<>();
for (BindingImpl<?, ?, ?> binding : bindings) {
- results.add(binding.getTargetValue());
+ results.add(binding.doValidation());
}
return results;
}
@@ -987,19 +987,19 @@ public class Binder<BEAN> implements Serializable {
* Only the one validation error message is shown in this label at a time.
* <p>
* This is a convenience method for
- * {@link #setStatusHandler(BinderStatusHandler)}, which means that this
- * method cannot be used after the handler has been set. Also the handler
- * cannot be set after this label has been set.
+ * {@link #setValidationStatusHandler(BinderStatusHandler)}, which means
+ * that this method cannot be used after the handler has been set. Also the
+ * handler cannot be set after this label has been set.
*
* @param statusLabel
* the status label to set
- * @see #setStatusHandler(BinderStatusHandler)
+ * @see #setValidationStatusHandler(BinderStatusHandler)
* @see Binding#withStatusLabel(Label)
*/
public void setStatusLabel(Label statusLabel) {
if (statusHandler != null) {
throw new IllegalStateException("Cannot set status label if a "
- + BinderStatusHandler.class.getSimpleName()
+ + BinderValidationStatusHandler.class.getSimpleName()
+ " has already been set.");
}
this.statusLabel = statusLabel;
@@ -1032,15 +1032,16 @@ public class Binder<BEAN> implements Serializable {
* @throws NullPointerException
* for <code>null</code> status handler
* @see #setStatusLabel(Label)
- * @see Binding#withStatusHandler(StatusChangeHandler)
+ * @see Binding#withValidationStatusHandler(ValidationStatusHandler)
*/
- public void setStatusHandler(BinderStatusHandler statusHandler) {
+ public void setValidationStatusHandler(
+ BinderValidationStatusHandler statusHandler) {
Objects.requireNonNull(statusHandler, "Cannot set a null "
- + BinderStatusHandler.class.getSimpleName());
+ + BinderValidationStatusHandler.class.getSimpleName());
if (statusLabel != null) {
- throw new IllegalStateException(
- "Cannot set " + BinderStatusHandler.class.getSimpleName()
- + " if a status label has already been set.");
+ throw new IllegalStateException("Cannot set "
+ + BinderValidationStatusHandler.class.getSimpleName()
+ + " if a status label has already been set.");
}
this.statusHandler = statusHandler;
}
@@ -1048,15 +1049,16 @@ public class Binder<BEAN> implements Serializable {
/**
* Gets the status handler of this form.
* <p>
- * If none has been set with {@link #setStatusHandler(BinderStatusHandler)},
- * the default implementation is returned.
+ * If none has been set with
+ * {@link #setValidationStatusHandler(BinderStatusHandler)}, the default
+ * implementation is returned.
*
* @return the status handler used, never <code>null</code>
- * @see #setStatusHandler(BinderStatusHandler)
+ * @see #setValidationStatusHandler(BinderStatusHandler)
*/
- public BinderStatusHandler getStatusHandler() {
+ public BinderValidationStatusHandler getValidationStatusHandler() {
return Optional.ofNullable(statusHandler)
- .orElse(this::defaultHandleBinderStatusChange);
+ .orElse(this::handleBinderValidationStatus);
}
/**
@@ -1115,12 +1117,12 @@ public class Binder<BEAN> implements Serializable {
}
/**
- * Default {@link StatusChangeHandler} functional method implementation.
+ * Default {@link ValidationStatusHandler} functional method implementation.
*
* @param status
* the validation status
*/
- protected void handleValidationStatusChange(ValidationStatus<?> status) {
+ protected void handleValidationStatus(ValidationStatus<?> status) {
HasValue<?> source = status.getField();
clearError(source);
if (status.isError()) {
@@ -1148,12 +1150,12 @@ public class Binder<BEAN> implements Serializable {
* status of validation results from binding and/or item level
* validators
*/
- protected void defaultHandleBinderStatusChange(
+ protected void handleBinderValidationStatus(
BinderValidationStatus<?> binderStatus) {
// let field events go to binding status handlers
binderStatus.getFieldValidationStatuses()
.forEach(status -> ((BindingImpl<?, ?, ?>) status.getBinding())
- .notifyStatusChangeHandler(status));
+ .notifyStatusHandler(status));
// show first possible error or OK status in the label if set
if (getStatusLabel().isPresent()) {
diff --git a/server/src/main/java/com/vaadin/data/BinderStatusHandler.java b/server/src/main/java/com/vaadin/data/BinderStatusHandler.java
deleted file mode 100644
index 5da5106176..0000000000
--- a/server/src/main/java/com/vaadin/data/BinderStatusHandler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data;
-
-import java.io.Serializable;
-import java.util.function.Consumer;
-
-import com.vaadin.data.Binder.Binding;
-
-/**
- * Status change handler for forms.
- * <p>
- * Register a handler using {@link Binder#setStatusHandler(BinderStatusHandler)}
- * to be able to customize the status change handling such as displaying
- * validation messages.
- * <p>
- * The list will contain results for either binding level or binder level, but
- * never both mixed. This is because binder level validation is not run if
- * binding level validation fails.
- *
- * @see Binder#setStatusHandler(BinderStatusHandler)
- * @see Binder#setStatusLabel(com.vaadin.ui.Label)
- * @see Binding#withStatusHandler(StatusChangeHandler)
- *
- * @author Vaadin Ltd
- * @since 8.0
- *
- */
-public interface BinderStatusHandler
- extends Consumer<BinderValidationStatus<?>>, Serializable {
-
-}
diff --git a/server/src/main/java/com/vaadin/data/BinderValidationStatus.java b/server/src/main/java/com/vaadin/data/BinderValidationStatus.java
index 8b589f574c..9b7e40f516 100644
--- a/server/src/main/java/com/vaadin/data/BinderValidationStatus.java
+++ b/server/src/main/java/com/vaadin/data/BinderValidationStatus.java
@@ -23,6 +23,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import com.vaadin.data.Binder.Binding;
+import com.vaadin.data.validator.BeanValidator;
/**
* Binder validation status change. Represents the outcome of binder level
@@ -33,8 +34,8 @@ import com.vaadin.data.Binder.Binding;
* Note: if there are any field level validation errors, the bean level
* validation is not run.
* <p>
- * Use {@link Binder#setStatusHandler(BinderStatusHandler)} to handle form level
- * validation status changes.
+ * Use {@link Binder#setValidationStatusHandler(BinderStatusHandler)} to handle
+ * form level validation status changes.
*
* @author Vaadin Ltd
*
@@ -42,7 +43,7 @@ import com.vaadin.data.Binder.Binding;
* the bean type of the binder
*
* @see BinderValidationStatusHandler
- * @see Binder#setStatusHandler(BinderStatusHandler)
+ * @see Binder#setValidationStatusHandler(BinderStatusHandler)
* @see Binder#validate()
* @see ValidationStatus
*
@@ -145,6 +146,9 @@ public class BinderValidationStatus<BEAN> implements Serializable {
/**
* Gets the field level validation statuses.
+ * <p>
+ * The field level validtors have been added with
+ * {@link Binding#withValidator(Validator)}.
*
* @return the field validation statuses
*/
@@ -154,6 +158,11 @@ public class BinderValidationStatus<BEAN> implements Serializable {
/**
* Gets the bean level validation results.
+ * <p>
+ * The bean level validators have been added with
+ * {@link Binder#withValidator(Validator)} or in case of a
+ * {@link BeanBinder} they might be automatically added {@link BeanValidator
+ * BeanValidators}.
*
* @return the bean level validation results
*/
@@ -163,6 +172,9 @@ public class BinderValidationStatus<BEAN> implements Serializable {
/**
* Gets the failed field level validation statuses.
+ * <p>
+ * The field level validtors have been added with
+ * {@link Binding#withValidator(Validator)}.
*
* @return a list of failed field level validation statuses
*/
@@ -172,9 +184,14 @@ public class BinderValidationStatus<BEAN> implements Serializable {
}
/**
- * Gets the failed bean level validation statuses.
+ * Gets the failed bean level validation results.
+ * <p>
+ * The bean level validators have been added with
+ * {@link Binder#withValidator(Validator)} or in case of a
+ * {@link BeanBinder} they might be automatically added {@link BeanValidator
+ * BeanValidators}.
*
- * @return a list of failed bean level validation statuses
+ * @return a list of failed bean level validation results
*/
public List<Result<?>> getBeanValidationErrors() {
return binderStatuses.stream().filter(Result::isError)
diff --git a/server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java b/server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java
index 9528c5a884..691b7bd6c0 100644
--- a/server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java
+++ b/server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java
@@ -23,7 +23,7 @@ import com.vaadin.ui.AbstractComponent;
/**
* Handler for {@link BinderValidationStatus} changes.
* <p>
- * {{@link Binder#setStatusHandler(BinderStatusHandler) Register} an instance of
+ * {{@link Binder#setValidationStatusHandler(BinderStatusHandler) Register} an instance of
* this class to be able to customize validation status handling.
* <p>
* The default handler will show
@@ -35,16 +35,13 @@ import com.vaadin.ui.AbstractComponent;
*
* @author Vaadin Ltd
*
- * @param <BEAN>
- * the bean type of the binder
- *
* @see BinderValidationStatus
* @see Binder#validate()
* @see ValidationStatus
*
* @since 8.0
*/
-public interface BinderValidationStatusHandler<BEAN>
- extends Consumer<BinderValidationStatus<BEAN>>, Serializable {
+public interface BinderValidationStatusHandler
+ extends Consumer<BinderValidationStatus<?>>, Serializable {
}
diff --git a/server/src/main/java/com/vaadin/data/Result.java b/server/src/main/java/com/vaadin/data/Result.java
index 5803eace11..7f63efa6a6 100644
--- a/server/src/main/java/com/vaadin/data/Result.java
+++ b/server/src/main/java/com/vaadin/data/Result.java
@@ -19,7 +19,6 @@ package com.vaadin.data;
import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;
-import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -123,19 +122,6 @@ public interface Result<R> extends Serializable {
<S> Result<S> flatMap(Function<R, Result<S>> mapper);
/**
- * Applies the given function to this result, regardless if this is an error
- * or not. Passes the value and the message to the given function as
- * parameters.
- *
- * @param <S>
- * the type of the mapped value
- * @param mapper
- * the mapping function
- * @return the mapped result
- */
- <S> S biMap(BiFunction<R, String, S> mapper);
-
- /**
* Invokes either the first callback or the second one, depending on whether
* this Result denotes a success or a failure, respectively.
*
diff --git a/server/src/main/java/com/vaadin/data/SimpleResult.java b/server/src/main/java/com/vaadin/data/SimpleResult.java
index ceedcb5ae3..935fb545e3 100644
--- a/server/src/main/java/com/vaadin/data/SimpleResult.java
+++ b/server/src/main/java/com/vaadin/data/SimpleResult.java
@@ -17,7 +17,6 @@ package com.vaadin.data;
import java.util.Objects;
import java.util.Optional;
-import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -66,11 +65,6 @@ class SimpleResult<R> implements Result<R> {
}
@Override
- public <S> S biMap(BiFunction<R, String, S> mapper) {
- return mapper.apply(value, message);
- }
-
- @Override
public void handle(Consumer<R> ifOk, Consumer<String> ifError) {
Objects.requireNonNull(ifOk, "ifOk cannot be null");
Objects.requireNonNull(ifError, "ifError cannot be null");
diff --git a/server/src/main/java/com/vaadin/data/ValidationException.java b/server/src/main/java/com/vaadin/data/ValidationException.java
index 68f7ad9e33..354420a41c 100644
--- a/server/src/main/java/com/vaadin/data/ValidationException.java
+++ b/server/src/main/java/com/vaadin/data/ValidationException.java
@@ -31,25 +31,24 @@ import java.util.stream.Collectors;
*/
public class ValidationException extends Exception {
- private final List<ValidationStatus<?>> bindingValidationErrors;
- private final List<Result<?>> binderValidationErrors;
+ private final List<ValidationStatus<?>> fieldValidationErrors;
+ private final List<Result<?>> beanValidationErrors;
/**
* Constructs a new exception with validation {@code errors} list.
*
- * @param bindingValidationErrors
+ * @param fieldValidationErrors
* binding validation errors list
- * @param binderValidationErrors
+ * @param beanValidationErrors
* binder validation errors list
*/
- public ValidationException(
- List<ValidationStatus<?>> bindingValidationErrors,
- List<Result<?>> binderValidationErrors) {
+ public ValidationException(List<ValidationStatus<?>> fieldValidationErrors,
+ List<Result<?>> beanValidationErrors) {
super("Validation has failed for some fields");
- this.bindingValidationErrors = Collections
- .unmodifiableList(bindingValidationErrors);
- this.binderValidationErrors = Collections
- .unmodifiableList(binderValidationErrors);
+ this.fieldValidationErrors = Collections
+ .unmodifiableList(fieldValidationErrors);
+ this.beanValidationErrors = Collections
+ .unmodifiableList(beanValidationErrors);
}
/**
@@ -66,24 +65,24 @@ public class ValidationException extends Exception {
}
/**
- * Returns a list of the binding level validation errors which caused the
- * exception, or an empty list if was caused by
- * {@link #getBeanValidationErrors() binder level validation errors}.
+ * Returns a list of the field level validation errors which caused the
+ * exception, or an empty list if the exception was caused by
+ * {@link #getBeanValidationErrors() bean level validation errors}.
*
* @return binding validation errors list
*/
public List<ValidationStatus<?>> getFieldValidationErrors() {
- return bindingValidationErrors;
+ return fieldValidationErrors;
}
/**
- * Returns a list of the binding level validation errors which caused the
- * exception, or an empty list if was caused by
- * {@link #getBeanValidationErrors() binder level validation errors}.
+ * Returns a list of the bean level validation errors which caused the
+ * exception, or an empty list if the exception was caused by
+ * {@link #getBindingValidationErrors() binder level validation errors}.
*
* @return binder validation errors list
*/
public List<Result<?>> getBeanValidationErrors() {
- return binderValidationErrors;
+ return beanValidationErrors;
}
}
diff --git a/server/src/main/java/com/vaadin/data/ValidationStatus.java b/server/src/main/java/com/vaadin/data/ValidationStatus.java
index f4b74c9d2c..f1f3da2d09 100644
--- a/server/src/main/java/com/vaadin/data/ValidationStatus.java
+++ b/server/src/main/java/com/vaadin/data/ValidationStatus.java
@@ -23,17 +23,17 @@ import com.vaadin.data.Binder.Binding;
/**
* Represents the outcome of field level validation. Use
- * {@link Binding#withStatusChangeHandler(ValidationStatusHandler)} to register
- * a handler for field level validation status changes.
+ * {@link Binding#withValidationStatusHandler(ValidationStatusHandler)} to
+ * register a handler for field level validation status changes.
*
* @author Vaadin Ltd
*
* @param <TARGET>
* the target data type of the binding for which the validation
- * status changed, matches the field type until a converter has been
+ * status changed, matches the field type unless a converter has been
* set
*
- * @see Binding#withStatusChangeHandler(ValidationStatusHandler)
+ * @see Binding#withValidationStatusHandler(ValidationStatusHandler)
* @see Binding#validate()
* @see ValidationStatusHandler
* @see BinderValidationStatus
diff --git a/server/src/main/java/com/vaadin/data/ValidationStatusHandler.java b/server/src/main/java/com/vaadin/data/ValidationStatusHandler.java
index 932fe64575..eb38e044f4 100644
--- a/server/src/main/java/com/vaadin/data/ValidationStatusHandler.java
+++ b/server/src/main/java/com/vaadin/data/ValidationStatusHandler.java
@@ -24,14 +24,15 @@ import com.vaadin.ui.AbstractComponent;
/**
* Handler for {@link ValidationStatus} changes.
* <p>
- * {@link Binding#withStatusHandler(StatusChangeHandler) Register} an instance
- * of this class to be able to override the default handling, which is to show
+ * {@link Binding#withValidationStatusHandler(withValidationStatusHandler)
+ * Register} an instance of this class to be able to override the default
+ * handling, which is to show
* {@link AbstractComponent#setComponentError(com.vaadin.server.ErrorMessage) an
* error message} for failed field validations.
*
* @author Vaadin Ltd
*
- * @see Binding#withStatusHandler(StatusChangeHandler)
+ * @see Binding#withValidationStatusHandler(withValidationStatusHandler)
* @see ValidationStatus
*
* @since 8.0
diff --git a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
index d11a0ed6da..e5c0457cfb 100644
--- a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
@@ -426,18 +426,18 @@ public class BinderBookOfVaadinTest {
}
@Test
- public void withBindingStatusChangeHandlerExample() {
+ public void withBindingStatusHandlerExample() {
Label nameStatus = new Label();
AtomicReference<ValidationStatus<?>> statusCapture = new AtomicReference<>();
String msg = "Full name must contain at least three characters";
binder.forField(field).withValidator(name -> name.length() >= 3, msg)
- .withStatusHandler(statusChange -> {
- nameStatus.setValue(statusChange.getMessage().orElse(""));
+ .withValidationStatusHandler(status -> {
+ nameStatus.setValue(status.getMessage().orElse(""));
// Only show the label when validation has failed
- boolean error = statusChange.getStatus() == Status.ERROR;
+ boolean error = status.getStatus() == Status.ERROR;
nameStatus.setVisible(error);
- statusCapture.set(statusChange);
+ statusCapture.set(status);
}).bind(BookPerson::getLastName, BookPerson::setLastName);
field.setValue("aa");
@@ -640,12 +640,13 @@ public class BinderBookOfVaadinTest {
}
@Test
- public void withBinderStatusChangeHandlerExample() {
+ public void withBinderStatusHandlerExample() {
Label formStatusLabel = new Label();
- BinderStatusHandler defaultHandler = binder.getStatusHandler();
+ BinderValidationStatusHandler defaultHandler = binder
+ .getValidationStatusHandler();
- binder.setStatusHandler(status -> {
+ binder.setValidationStatusHandler(status -> {
// create an error message on failed bean level validations
List<Result<?>> errors = status.getBeanValidationErrors();
String errorMessage = errors.stream().map(Result::getMessage)
diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java
index 81b4d965b4..d780345f78 100644
--- a/server/src/test/java/com/vaadin/data/BinderTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderTest.java
@@ -575,10 +575,10 @@ public class BinderTest {
}
@Test
- public void bindingWithStatusChangeHandler_handlerGetsEvents() {
+ public void bindingWithStatusHandler_handlerGetsEvents() {
AtomicReference<ValidationStatus<?>> statusCapture = new AtomicReference<>();
Binding<Person, String, String> binding = binder.forField(nameField)
- .withValidator(notEmpty).withStatusHandler(evt -> {
+ .withValidator(notEmpty).withValidationStatusHandler(evt -> {
Assert.assertNull(statusCapture.get());
statusCapture.set(evt);
});
@@ -611,9 +611,9 @@ public class BinderTest {
}
@Test
- public void bindingWithStatusChangeHandler_defaultStatusChangeHandlerIsReplaced() {
+ public void bindingWithStatusHandler_defaultStatusHandlerIsReplaced() {
Binding<Person, String, String> binding = binder.forField(nameField)
- .withValidator(notEmpty).withStatusHandler(evt -> {
+ .withValidator(notEmpty).withValidationStatusHandler(evt -> {
});
binding.bind(Person::getFirstName, Person::setFirstName);
@@ -657,7 +657,7 @@ public class BinderTest {
}
@Test
- public void bindingWithStatusLabel_defaultStatusChangeHandlerIsReplaced() {
+ public void bindingWithStatusLabel_defaultStatusHandlerIsReplaced() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField)
@@ -677,12 +677,12 @@ public class BinderTest {
}
@Test(expected = IllegalStateException.class)
- public void bindingWithStatusChangeHandler_addAfterBound() {
+ public void bindingWithStatusHandler_addAfterBound() {
Binding<Person, String, String> binding = binder.forField(nameField)
.withValidator(notEmpty);
binding.bind(Person::getFirstName, Person::setFirstName);
- binding.withStatusHandler(evt -> Assert.fail());
+ binding.withValidationStatusHandler(evt -> Assert.fail());
}
@Test(expected = IllegalStateException.class)
@@ -702,33 +702,33 @@ public class BinderTest {
Binding<Person, String, String> binding = binder.forField(nameField);
- binding.withStatusHandler(event -> {
+ binding.withValidationStatusHandler(event -> {
});
binding.withStatusLabel(label);
}
@Test(expected = IllegalStateException.class)
- public void bindingWithStatusChangeHandler_setAfterLabel() {
+ public void bindingWithStatusHandler_setAfterLabel() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField);
binding.withStatusLabel(label);
- binding.withStatusHandler(event -> {
+ binding.withValidationStatusHandler(event -> {
});
}
@Test(expected = IllegalStateException.class)
- public void bingingWithStatusChangeHandler_setAfterOtherHandler() {
+ public void bingingWithStatusHandler_setAfterOtherHandler() {
Binding<Person, String, String> binding = binder.forField(nameField);
- binding.withStatusHandler(event -> {
+ binding.withValidationStatusHandler(event -> {
});
- binding.withStatusHandler(event -> {
+ binding.withValidationStatusHandler(event -> {
});
}
@@ -871,17 +871,17 @@ public class BinderTest {
public void binderWithStatusHandler_fieldValidationNoBeanValidation_handlerGetsStatusUpdates() {
AtomicReference<BinderValidationStatus<?>> statusCapture = new AtomicReference<>();
binder.forField(nameField).withValidator(notEmpty)
- .withStatusHandler(evt -> {
+ .withValidationStatusHandler(evt -> {
Assert.fail(
"Using a custom status change handler so no change should end up here");
}).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).withConverter(stringToInteger)
- .withValidator(notNegative).withStatusHandler(evt -> {
+ .withValidator(notNegative).withValidationStatusHandler(evt -> {
Assert.fail(
"Using a custom status change handler so no change should end up here");
}).bind(Person::getAge, Person::setAge);
- binder.setStatusHandler(r -> {
+ binder.setValidationStatusHandler(r -> {
statusCapture.set(r);
});
binder.bind(p);
@@ -961,12 +961,12 @@ public class BinderTest {
public void binderWithStatusHandler_fieldAndBeanLevelValidation_handlerGetsStatusUpdates() {
AtomicReference<BinderValidationStatus<?>> statusCapture = new AtomicReference<>();
binder.forField(nameField).withValidator(notEmpty)
- .withStatusHandler(evt -> {
+ .withValidationStatusHandler(evt -> {
Assert.fail(
"Using a custom status change handler so no change should end up here");
}).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).withConverter(stringToInteger)
- .withValidator(notNegative).withStatusHandler(evt -> {
+ .withValidator(notNegative).withValidationStatusHandler(evt -> {
Assert.fail(
"Using a custom status change handler so no change should end up here");
}).bind(Person::getAge, Person::setAge);
@@ -975,7 +975,7 @@ public class BinderTest {
? Result.ok(bean)
: Result.error("Need first name and age"));
- binder.setStatusHandler(r -> {
+ binder.setValidationStatusHandler(r -> {
statusCapture.set(r);
});
binder.bind(p);
@@ -1055,9 +1055,9 @@ public class BinderTest {
}
@Test
- public void binderWithStatusChangeHandler_defaultStatusChangeHandlerIsReplaced() {
+ public void binderWithStatusHandler_defaultStatusHandlerIsReplaced() {
Binding<Person, String, String> binding = binder.forField(nameField)
- .withValidator(notEmpty).withStatusHandler(evt -> {
+ .withValidator(notEmpty).withValidationStatusHandler(evt -> {
});
binding.bind(Person::getFirstName, Person::setFirstName);
@@ -1074,7 +1074,7 @@ public class BinderTest {
}
@Test
- public void binderWithStatusLabel_defaultStatusChangeHandlerIsReplaced() {
+ public void binderWithStatusLabel_defaultStatusHandlerIsReplaced() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField)
@@ -1094,12 +1094,12 @@ public class BinderTest {
}
@Test(expected = IllegalStateException.class)
- public void binderWithStatusChangeHandler_addAfterBound() {
+ public void binderWithStatusHandler_addAfterBound() {
Binding<Person, String, String> binding = binder.forField(nameField)
.withValidator(notEmpty);
binding.bind(Person::getFirstName, Person::setFirstName);
- binding.withStatusHandler(evt -> Assert.fail());
+ binding.withValidationStatusHandler(evt -> Assert.fail());
}
@Test(expected = IllegalStateException.class)
@@ -1120,14 +1120,14 @@ public class BinderTest {
Binding<Person, String, String> binding = binder.forField(nameField);
binding.bind(Person::getFirstName, Person::setFirstName);
- binder.setStatusHandler(event -> {
+ binder.setValidationStatusHandler(event -> {
});
binder.setStatusLabel(label);
}
@Test(expected = IllegalStateException.class)
- public void binderWithStatusChangeHandler_setAfterLabel() {
+ public void binderWithStatusHandler_setAfterLabel() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField);
@@ -1135,27 +1135,27 @@ public class BinderTest {
binder.setStatusLabel(label);
- binder.setStatusHandler(event -> {
+ binder.setValidationStatusHandler(event -> {
});
}
@Test(expected = NullPointerException.class)
- public void binderWithNullStatusChangeHandler_throws() {
- binder.setStatusHandler(null);
+ public void binderWithNullStatusHandler_throws() {
+ binder.setValidationStatusHandler(null);
}
@Test
- public void binderWithStatusChangeHandler_replaceHandler() {
+ public void binderWithStatusHandler_replaceHandler() {
AtomicReference<BinderValidationStatus<?>> capture = new AtomicReference<>();
Binding<Person, String, String> binding = binder.forField(nameField);
binding.bind(Person::getFirstName, Person::setFirstName);
- binder.setStatusHandler(results -> {
+ binder.setValidationStatusHandler(results -> {
Assert.fail();
});
- binder.setStatusHandler(results -> {
+ binder.setValidationStatusHandler(results -> {
capture.set(results);
});