Package org.vaadin.firitin.form
Class FormBinder<T>
java.lang.Object
org.vaadin.firitin.form.FormBinder<T>
- Type Parameters:
- T- The class/record type bound by this binder.
- All Implemented Interfaces:
- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,,- T> - Serializable
public class FormBinder<T>
extends Object
implements com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,T> 
A new start for the 
Binder.
 Note, that this is still a fairly new class, so there might be API changes to it.
 Design principles:
- Only support "non-buffered mode" so that validation logic can use the bean/record + simplicity of the implementation
- Validation is "just validation", and not concern of this class. BUT, API must support binding external validation logic, like Bean Validation API
- Must support Records and immutable objects as well
- No requirements for BeanValidation or Spring DataBinding stuff, but optional support (or extensible for those)
- Aiming for binding anything without property names (for good solution this needs to be resolved at language level and supported with thing like Bean Validation first)
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface com.vaadin.flow.component.HasValuecom.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
- 
Constructor SummaryConstructorsConstructorDescriptionFormBinder(Class<T> tClass, com.vaadin.flow.component.Component... containerComponents) Constructs a new binder.FormBinder(Class<T> tClass, Object editorObject) Deprecated.not sure yet if this is a good idea, added for backwards compatibilityFormBinder(Class<T> tClass, Map<String, com.vaadin.flow.component.HasValue> propertyNameToEditor) Binds type to given property editorsFormBinder(T dto, com.vaadin.flow.component.Component... containerComponents) Binds given dto to the UI fields found from given component(s).
- 
Method SummaryModifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener<? super FormBinderValueChangeEvent<T>> listener) voidRemoves all validation errors from bound fields andgetClassLevelViolationDisplay().protected voidconfigureEditor(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property, com.vaadin.flow.component.HasValue hasValue) protected Tprotected Tcom.vaadin.flow.component.HasComponentsGets the class level violation display.com.vaadin.flow.component.HasValueReturns a map containing input conversion errors (propertyname-error).getValue()protected voidhandleClassLevelValidations(Set<jakarta.validation.ConstraintViolation<T>> violations) protected ObjecthandleInputConversionError(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property, com.vaadin.flow.data.binder.ValueContext ctx, String conversionErrorMsg) Handles input conversion error.booleanChecks if there have recently been errors to convert value from the UI to the domain object.protected booleanbooleanprotected static booleanisRequired(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property) booleanbooleanisValid()voidsetClassLevelViolationDisplay(com.vaadin.flow.component.HasComponents display) Sets the container component where "class level" constraint violations are displayed.voidsetConstraintViolations(Set<jakarta.validation.ConstraintViolation<T>> violations) Set the constraint violations found during validation.voidsetConverter(String property, com.vaadin.flow.data.converter.Converter<?, ?> strToDt) Sets a converter to use between the domain model property and the corresponding UI component editing it.voidsetIgnoreServerOriginatedChanges(boolean ignore) A flag to control whether server originated value change events should be ignored.voidsetRawConstraintViolations(Map<String, String> propertyToViolation) Deprecated.try to use the standard Java Bean Validation API based method insteadvoidsetReadOnly(boolean readOnly) voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible) voidSets the value object bound to this formvoidunBind()Clears bindings, might be needed to clean up references if e.g.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.HasValueclear, getEmptyValue, getOptionalValue, isEmpty
- 
Constructor Details- 
FormBinderConstructs a new binder.- Parameters:
- tClass- the class of the bound entity/bean, set later with- setValue(Object)
- containerComponents- the components whose class contains the fields to bound
 
- 
FormBinderDeprecated.not sure yet if this is a good idea, added for backwards compatibilityConstructs a new binder.- Parameters:
- tClass- the class of the bound entity/bean, set later with- setValue(Object)
- editorObject- the editor object that contains the fields to bound, does not need to be a component
 
- 
FormBinderpublic FormBinder(Class<T> tClass, Map<String, com.vaadin.flow.component.HasValue> propertyNameToEditor) Binds type to given property editors- Parameters:
- tClass- the type to bind
- propertyNameToEditor- pre-instantiated editors to bind
 
- 
FormBinderBinds given dto to the UI fields found from given component(s).- Parameters:
- dto- the object to bind. The type of the FormBinder will be taken from this object.
- containerComponents- the components whose class contains the fields to bound
 
 
- 
- 
Method Details- 
isRequiredprotected static boolean isRequired(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property) 
- 
configureEditorprotected void configureEditor(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property, com.vaadin.flow.component.HasValue hasValue) 
- 
handleInputConversionErrorprotected Object handleInputConversionError(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition property, com.vaadin.flow.data.binder.ValueContext ctx, String conversionErrorMsg) Handles input conversion error. By default, the error message saved and set to the field.- Parameters:
- property-
- ctx-
- conversionErrorMsg-
- Returns:
- the value to be set to the edited object, null by default
 
- 
getValue- Specified by:
- getValuein interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
setValueSets the value object bound to this form- Specified by:
- setValuein interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
- Parameters:
- valueObject- the new value
 
- 
withValue
- 
addValueChangeListenerpublic com.vaadin.flow.shared.Registration addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener<? super FormBinderValueChangeEvent<T>> listener) - Specified by:
- addValueChangeListenerin interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
isReadOnlypublic boolean isReadOnly()- Specified by:
- isReadOnlyin interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
setReadOnlypublic void setReadOnly(boolean readOnly) - Specified by:
- setReadOnlyin interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
isRequiredIndicatorVisiblepublic boolean isRequiredIndicatorVisible()- Specified by:
- isRequiredIndicatorVisiblein interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
setRequiredIndicatorVisiblepublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible) - Specified by:
- setRequiredIndicatorVisiblein interface- com.vaadin.flow.component.HasValue<FormBinderValueChangeEvent<T>,- T> 
 
- 
isImmutableprotected boolean isImmutable()
- 
constructRecord
- 
constructPojo
- 
setConstraintViolationsSet the constraint violations found during validation. If violation is bound to a bound property, it is shown next to the field, otherwise shown at "form level", seesetClassLevelViolationDisplay(HasComponents).- Parameters:
- violations- the constraint violations that should be shown in the UI
 
- 
getClassLevelViolationDisplaypublic com.vaadin.flow.component.HasComponents getClassLevelViolationDisplay()Gets the class level violation display. If not set, the first container component is used if of appropriate type.- Returns:
- the component where constraint violations will be displayed
 
- 
setClassLevelViolationDisplaypublic void setClassLevelViolationDisplay(com.vaadin.flow.component.HasComponents display) Sets the container component where "class level" constraint violations are displayed.- Parameters:
- display- the component where the "class level" constraint violations will be displayed.
 
- 
handleClassLevelValidations
- 
setRawConstraintViolationsDeprecated.try to use the standard Java Bean Validation API based method insteadAn alternative API to report constraint violations without BeanValidation on the classpath.- Parameters:
- propertyToViolation-
 
- 
clearValidationErrorspublic void clearValidationErrors()Removes all validation errors from bound fields andgetClassLevelViolationDisplay().
- 
setConverterSets a converter to use between the domain model property and the corresponding UI component editing it.- Parameters:
- property- the property
- strToDt- the converter
 
- 
hasInputConversionErrorspublic boolean hasInputConversionErrors()Checks if there have recently been errors to convert value from the UI to the domain object.- Returns:
- true if there are active conversion errors
 
- 
getInputConversionErrorsReturns a map containing input conversion errors (propertyname-error).- Returns:
- input conversion errors
 
- 
isValidpublic boolean isValid()- Returns:
- true if the binging looks valid for the user: no displayed constraint violations nor input conversion errors.
 
- 
setIgnoreServerOriginatedChangespublic void setIgnoreServerOriginatedChanges(boolean ignore) A flag to control whether server originated value change events should be ignored. Currently only known to be needed for testing, might be removed in the future.- Parameters:
- ignore- true if non-client originated events should be ignored
 
- 
unBindpublic void unBind()Clears bindings, might be needed to clean up references if e.g. re-using fields
- 
getBoundProperties
- 
getEditor
 
-