]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix inconsistent API naming in Binder and remove unused handler
authorPekka Hyvönen <pekka@vaadin.com>
Tue, 13 Sep 2016 08:12:00 +0000 (11:12 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 13 Sep 2016 10:13:32 +0000 (10:13 +0000)
Mostly based on comments on a previous patch that was merged.

Change-Id: I146995853b3318d89061f1d06ab4bbd859168661

13 files changed:
documentation/datamodel/datamodel-forms.asciidoc
server/src/main/java/com/vaadin/data/BeanBinder.java
server/src/main/java/com/vaadin/data/Binder.java
server/src/main/java/com/vaadin/data/BinderStatusHandler.java [deleted file]
server/src/main/java/com/vaadin/data/BinderValidationStatus.java
server/src/main/java/com/vaadin/data/BinderValidationStatusHandler.java
server/src/main/java/com/vaadin/data/Result.java
server/src/main/java/com/vaadin/data/SimpleResult.java
server/src/main/java/com/vaadin/data/ValidationException.java
server/src/main/java/com/vaadin/data/ValidationStatus.java
server/src/main/java/com/vaadin/data/ValidationStatusHandler.java
server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
server/src/test/java/com/vaadin/data/BinderTest.java

index 62d844dee659518960549489066b5684e77a255d..3c2dd95bb573346962d0d2800b0a8321fec656c5 100644 (file)
@@ -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)
index cbabdb80cb02f11b2c7f5019532980c79f3cd133..dd5790b8b62c070bcdf9692389bbcaf230a46f50 100644 (file)
@@ -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);
     }
 
     /**
index f58c69bb7b24e2bbd047f237fa9445f60517621e..ba579148b917bfc92e1cc64c3e00238dd7e5ae0c 100644 (file)
@@ -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 (file)
index 5da5106..0000000
+++ /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 {
-
-}
index 8b589f574c7f1bb285f6afd5aea1f25659fac54d..9b7e40f516c101243c1930cebec7227ab2d6e63c 100644 (file)
@@ -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)
index 9528c5a884ee287892f9b5479883aa6a06afbd9d..691b7bd6c062c3fdcfd4fb330e420b658df909a0 100644 (file)
@@ -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 {
 
 }
index 5803eace11eef1b73f54194d3056b7b3ce019342..7f63efa6a6ef32237d997d2dcb1e7bd9ec09d93e 100644 (file)
@@ -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;
@@ -122,19 +121,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.
index ceedcb5ae3f8b95bd349b1c947a6de33ac9e2352..935fb545e3b832bede0b2a01f7e264f7ea2ab643 100644 (file)
@@ -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;
 
@@ -65,11 +64,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");
index 68f7ad9e3381ee025ec0ffb483ed123f85709cd8..354420a41cfba65162e731e3f348d36946e4dd2e 100644 (file)
@@ -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;
     }
 }
index f4b74c9d2ca9e6d8392589f76d7569f1573c0fa2..f1f3da2d09aa5714c4b79dd9ab3a67cabc3b7db2 100644 (file)
@@ -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
index 932fe64575c961a3fff746f2b2f2901ce9fc4ebf..eb38e044f4604a2c603030431505e065587984e5 100644 (file)
@@ -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
index d11a0ed6da7f49b37ff384d1206d0b9151df2ba7..e5c0457cfb9beb89d33f4cc04f69699f815d6ccc 100644 (file)
@@ -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)
index 81b4d965b45c91fbe7898e46c8986feaea69e958..d780345f78c28e35c12c7c63f32f72ae1d9e729e 100644 (file)
@@ -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);
         });