Mostly based on comments on a previous patch that was merged.
Change-Id: I146995853b3318d89061f1d06ab4bbd859168661
.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);
----
[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)
* 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
public <FIELDVALUE> BeanBinding<BEAN, FIELDVALUE, FIELDVALUE> forField(
HasValue<FIELDVALUE> field) {
return createBinding(field, Converter.identity(),
- this::handleValidationStatusChange);
+ this::handleValidationStatus);
}
/**
* 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
*/
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());
}
/**
- * 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
* status change handler
* @return this binding, for chaining
*/
- public Binding<BEAN, FIELDVALUE, TARGET> withStatusHandler(
+ public Binding<BEAN, FIELDVALUE, TARGET> withValidationStatusHandler(
ValidationStatusHandler handler);
/**
* 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
}
@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;
@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;
* 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());
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));
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)));
setter.accept(bean, value);
}
- private void notifyStatusChangeHandler(ValidationStatus<?> status) {
+ private void notifyStatusHandler(ValidationStatus<?> status) {
statusHandler.accept(status);
}
}
private Label statusLabel;
- private BinderStatusHandler statusHandler;
+ private BinderValidationStatusHandler statusHandler;
private boolean hasChanges = false;
getStatusLabel().ifPresent(label -> label.setValue(""));
return createBinding(field, Converter.identity(),
- this::handleValidationStatusChange);
+ this::handleValidationStatus);
}
/**
bean = null;
bindings.forEach(BindingImpl::unbind);
}
- getStatusHandler()
+ getValidationStatusHandler()
.accept(BinderValidationStatus.createUnresolvedStatus(this));
}
setHasChanges(false);
bindings.forEach(binding -> binding.setFieldValue(bean));
- getStatusHandler()
+ getValidationStatusHandler()
.accept(BinderValidationStatus.createUnresolvedStatus(this));
}
validationStatus = new BinderValidationStatus<>(this,
bindingStatuses, validateItem(bean));
}
- getStatusHandler().accept(validationStatus);
+ getValidationStatusHandler().accept(validationStatus);
return validationStatus;
}
private List<ValidationStatus<?>> validateBindings() {
List<ValidationStatus<?>> results = new ArrayList<>();
for (BindingImpl<?, ?, ?> binding : bindings) {
- results.add(binding.getTargetValue());
+ results.add(binding.doValidation());
}
return results;
}
* 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;
* @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;
}
/**
* 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);
}
/**
}
/**
- * 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()) {
* 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()) {
+++ /dev/null
-/*
- * 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 {
-
-}
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
* 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
*
* the bean type of the binder
*
* @see BinderValidationStatusHandler
- * @see Binder#setStatusHandler(BinderStatusHandler)
+ * @see Binder#setValidationStatusHandler(BinderStatusHandler)
* @see Binder#validate()
* @see ValidationStatus
*
/**
* Gets the field level validation statuses.
+ * <p>
+ * The field level validtors have been added with
+ * {@link Binding#withValidator(Validator)}.
*
* @return the field validation statuses
*/
/**
* 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
*/
/**
* 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
*/
}
/**
- * 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)
/**
* 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
*
* @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 {
}
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;
*/
<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.
import java.util.Objects;
import java.util.Optional;
-import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
}
}
- @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");
*/
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);
}
/**
}
/**
- * 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;
}
}
/**
* 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
/**
* 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
}
@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");
}
@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)
}
@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);
});
}
@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);
}
@Test
- public void bindingWithStatusLabel_defaultStatusChangeHandlerIsReplaced() {
+ public void bindingWithStatusLabel_defaultStatusHandlerIsReplaced() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField)
}
@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)
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 -> {
});
}
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);
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);
? Result.ok(bean)
: Result.error("Need first name and age"));
- binder.setStatusHandler(r -> {
+ binder.setValidationStatusHandler(r -> {
statusCapture.set(r);
});
binder.bind(p);
}
@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);
}
@Test
- public void binderWithStatusLabel_defaultStatusChangeHandlerIsReplaced() {
+ public void binderWithStatusLabel_defaultStatusHandlerIsReplaced() {
Label label = new Label();
Binding<Person, String, String> binding = binder.forField(nameField)
}
@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)
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);
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);
});