Class Binder.BindingImpl<BEAN,FIELDVALUE,TARGET>

java.lang.Object
com.vaadin.flow.data.binder.Binder.BindingImpl<BEAN,FIELDVALUE,TARGET>
Type Parameters:
BEAN - the bean type, must match the Binder bean type
FIELDVALUE - the value type of the field
TARGET - the target data type of the binding, matches the field type unless a converter has been set
All Implemented Interfaces:
Binder.Binding<BEAN,TARGET>, Serializable
Enclosing class:
Binder<BEAN>

protected static class Binder.BindingImpl<BEAN,FIELDVALUE,TARGET> extends Object implements Binder.Binding<BEAN,TARGET>
An internal implementation of Binding.
See Also:
  • Constructor Details

  • Method Details

    • getField

      public com.vaadin.flow.component.HasValue<?,FIELDVALUE> getField()
      Description copied from interface: Binder.Binding
      Gets the field the binding uses.
      Specified by:
      getField in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      the field for the binding
    • findLocale

      protected static Locale findLocale()
      Finds an appropriate locale to be used in conversion and validation.
      Returns:
      the found locale, not null
    • validate

      public BindingValidationStatus<TARGET> validate(boolean fireEvent)
      Description copied from interface: Binder.Binding
      Validates the field value and returns a ValidationStatus instance representing the outcome of the validation.
      Specified by:
      validate in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      fireEvent - true to fire status event; false to not
      Returns:
      the validation result.
      See Also:
    • unbind

      public void unbind()
      Removes this binding from its binder and unregisters the ValueChangeListener from any bound HasValue, and ValidationStatusChangeListener from any bound HasValidator. It does nothing if it is called for an already unbound binding.
      Specified by:
      unbind in interface Binder.Binding<BEAN,FIELDVALUE>
    • createValueContext

      protected ValueContext createValueContext()
      Creates a value context from the current state of the binding and its field.
      Returns:
      the value context
    • getBinder

      protected Binder<BEAN> getBinder()
      Returns the Binder connected to this Binding instance.
      Returns:
      the binder
    • getValidationStatusHandler

      public BindingValidationStatusHandler getValidationStatusHandler()
      Description copied from interface: Binder.Binding
      Gets the validation status handler for this Binding.
      Specified by:
      getValidationStatusHandler in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      the validation status handler for this binding
    • read

      public void read(BEAN bean)
      Description copied from interface: Binder.Binding
      Reads the value from given item and stores it to the bound field.
      Specified by:
      read in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      bean - the bean to read from
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Description copied from interface: Binder.Binding
      Sets the read-only status on for this Binding. Setting a Binding read-only will mark the field read-only and not write any values from the fields to the bean.

      This helper method is the preferred way to control the read-only state of the bound field.

      Specified by:
      setReadOnly in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      readOnly - true to set binding read-only; false to enable writes
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: Binder.Binding
      Gets the current read-only status for this Binding.
      Specified by:
      isReadOnly in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      true if read-only; false if not
      See Also:
    • getGetter

      public com.vaadin.flow.function.ValueProvider<BEAN,TARGET> getGetter()
      Description copied from interface: Binder.Binding
      Gets the getter associated with this Binding.
      Specified by:
      getGetter in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      the getter
    • getSetter

      public Setter<BEAN,TARGET> getSetter()
      Description copied from interface: Binder.Binding
      Gets the setter associated with this Binding.
      Specified by:
      getSetter in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      the setter
    • setAsRequiredEnabled

      public void setAsRequiredEnabled(boolean asRequiredEnabled)
      Description copied from interface: Binder.Binding
      Enable or disable asRequired validator. The validator is enabled by default.
      Specified by:
      setAsRequiredEnabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      asRequiredEnabled - false if asRequired validator should be disabled, true otherwise (default)
      See Also:
    • isAsRequiredEnabled

      public boolean isAsRequiredEnabled()
      Description copied from interface: Binder.Binding
      Returns whether asRequired validator is currently enabled or not.
      Specified by:
      isAsRequiredEnabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      false if asRequired validator is disabled true otherwise (default)
      See Also:
    • setValidatorsDisabled

      public void setValidatorsDisabled(boolean validatorsDisabled)
      Description copied from interface: Binder.Binding
      Define whether validators are disabled or enabled for this specific binding.
      Specified by:
      setValidatorsDisabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      validatorsDisabled - A boolean value.
    • isValidatorsDisabled

      public boolean isValidatorsDisabled()
      Description copied from interface: Binder.Binding
      Returns if validators are currently disabled or not.
      Specified by:
      isValidatorsDisabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      A boolean value.
    • setDefaultValidatorEnabled

      public void setDefaultValidatorEnabled(Boolean defaultValidatorEnabled)
      Description copied from interface: Binder.Binding
      Sets up this binding to either enable or disable the default field validator (e.g. min/max validators in DatePicker). This binding-level setting will override the Binder-level setting for this property. Defaults to null.
      Specified by:
      setDefaultValidatorEnabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      defaultValidatorEnabled - true to enable default validator for this binding, false to disable it, null to reset (fall back to Binder-level setting)
      See Also:
    • isDefaultValidatorEnabled

      public Boolean isDefaultValidatorEnabled()
      Description copied from interface: Binder.Binding
      Returns if default validator of bound field is enabled.
      Specified by:
      isDefaultValidatorEnabled in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      true if default validator is enabled for this binding, false if it is disabled, null if falls back to Binder-level setting
    • setConvertBackToPresentation

      public void setConvertBackToPresentation(boolean convertBackToPresentation)
      Description copied from interface: Binder.Binding
      Define whether the value should be converted back to the presentation in the field when a converter is used in binding.

      As of version 6.0, when a converter is used on a binding and the user input value is modified by the converter, the value from the converter is applied back to the input. It is possible to control this behavior with this API.

      Specified by:
      setConvertBackToPresentation in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      convertBackToPresentation - A boolean value
      See Also:
    • isConvertBackToPresentation

      public boolean isConvertBackToPresentation()
      Description copied from interface: Binder.Binding
      Returns whether the value is converted back to the presentation in the field when a converter is used in binding.
      Specified by:
      isConvertBackToPresentation in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      A boolean value
    • hasChanges

      public boolean hasChanges() throws IllegalStateException
      Description copied from interface: Binder.Binding
      Checks whether the field that the binding uses has uncommitted changes.
      Specified by:
      hasChanges in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      true if the field the binding uses has uncommitted changes, otherwise false.
      Throws:
      IllegalStateException - if the binding is no longer attached to a Binder.
    • getEqualityPredicate

      public com.vaadin.flow.function.SerializableBiPredicate<TARGET,TARGET> getEqualityPredicate()
      Description copied from interface: Binder.Binding
      Used in comparison of the current value of a field with its initial value.

      Once set, the value of the field that binding uses will be compared with the initial value for hasChanged.

      Specified by:
      getEqualityPredicate in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      the predicate to use for equality comparison
    • getIsAppliedPredicate

      public com.vaadin.flow.function.SerializablePredicate<Binder.Binding<BEAN,TARGET>> getIsAppliedPredicate()
      Description copied from interface: Binder.Binding
      Gets predicate for testing Binder.Binding.isApplied(). By default, non-visible components are ignored during validation and bean writing.
      Specified by:
      getIsAppliedPredicate in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      predicate for testing Binder.Binding.isApplied()
    • setIsAppliedPredicate

      public void setIsAppliedPredicate(com.vaadin.flow.function.SerializablePredicate<Binder.Binding<BEAN,TARGET>> isAppliedPredicate)
      Description copied from interface: Binder.Binding
      Sets a custom predicate for testing Binder.Binding.isApplied(). Set to null to restore default functionality.
      Specified by:
      setIsAppliedPredicate in interface Binder.Binding<BEAN,FIELDVALUE>
      Parameters:
      isAppliedPredicate - custom predicate for testing Binder.Binding.isApplied()
    • valueSignal

      public com.vaadin.flow.signals.local.ValueSignal<TARGET> valueSignal()
      Description copied from interface: Binder.Binding
      Returns a signal holding the current converted and validated value of this binding's field.

      This method is primarily designed for implementing cross-field validation, where one field's validator needs to access the value of another field. It should be called from within a validator that is registered to a binding via Binder.BindingBuilder.withValidator(Validator).

      The Binder automatically runs validators inside a Signal.effect(Component, com.vaadin.flow.signals.function.EffectAction) context. This makes validators reactive to signal changes - when you call valueSignal() on another binding from within a validator, the validator will automatically re-run whenever that other binding's value changes.

      For cross-field validation to work automatically, the fields must be attached to the UI component tree. Detached fields will not trigger automatic re-validation, though manual validation via Binder.validate() will still work.

      Example - Cross-field validation:

       
       Binder<UserRegistration> binder = new Binder<>(
               UserRegistration.class);
       PasswordField passwordField = new PasswordField();
       PasswordField confirmField = new PasswordField();
      
       // Get reference to binding for cross-field validation
       Binding<UserRegistration, String> passwordBinding = binder
               .forField(passwordField).bind("password");
      
       binder.forField(confirmField).withValidator(
               text -> text.equals(passwordBinding.valueSignal().get()),
               "Both fields must match").bind("confirmPassword");
      
       add(passwordField, confirmField);
      
       binder.setBean(userRegistration);
      
       passwordField.setValue("secret"); // confirmField shows validation
                                         // error
      
       // Same works also with a Signal directly:
       ValueSignal<String> passwordSignal = new ValueSignal<>("");
       passwordField.bindValue(passwordSignal, passwordSignal::set);
       binder.forField(confirmField)
               .withValidator(text -> text.equals(passwordSignal.get()),
                       "Both fields must match")
               .bind("confirmPassword");
       passwordSignal.set("secret"); // confirmField shows validation
                                     // error
       
       
      Specified by:
      valueSignal in interface Binder.Binding<BEAN,FIELDVALUE>
      Returns:
      a signal holding the current converted and validated value of this binding's field
      See Also: