Class EasyForm.Field<V>
java.lang.Object
com.flowingcode.vaadin.addons.easyform.EasyForm.Field<V>
- Type Parameters:
V- the presentation value type of the field component
- All Implemented Interfaces:
Serializable
Fluent configuration wrapper for a single field of an
EasyForm.
Instances are obtained through EasyForm.configureField(String) and allow configuring
the visibility, presentation, validation, and component of the field generated for a bean
property:
form.configureField("email").withLabel("Email Address").withPlaceholder("user@example.com")
.asRequired("Email is required");
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionasRequired(String errorMessage) Makes this field required, showing the given message when it is empty.excluded()Excludes this field from the layout and from the binding.readOnly()Makes this field read-only: it is displayed and populated from the bean, but cannot be edited.visible()Makes this field visible and editable (the default state), reversingreadOnly()orexcluded().withColSpan(int colSpan) Sets the number of columns this field spans in the form layout.<W,C extends Component & HasValue<?, W>>
EasyForm.Field<W>withComponent(C component) Replaces the auto-generated component of this field with the given one, and types this wrapper after the value type of the new component.<P> EasyForm.Field<V>withConverter(Converter<V, P> converter) Sets a converter that adapts the presentation value of the component to the model type of the bean property (e.g. aStringfield bound to anIntegerproperty).withHelperText(String helperText) Sets the helper text of this field.Sets the label of this field, replacing the label generated from the property name.withPlaceholder(String placeholder) Sets the placeholder of this field.withValidator(Validator<V> validator) Adds a validator to this field.
-
Method Details
-
visible
Makes this field visible and editable (the default state), reversingreadOnly()orexcluded().- Returns:
- this, for method chaining
-
readOnly
Makes this field read-only: it is displayed and populated from the bean, but cannot be edited.- Returns:
- this, for method chaining
-
excluded
Excludes this field from the layout and from the binding. The property is neither displayed nor written when the form writes to a bean, so an excluded property keeps whatever value the target instance already had. Reverse it withvisible().- Returns:
- this, for method chaining
-
withLabel
Sets the label of this field, replacing the label generated from the property name.- Parameters:
label- the label to set- Returns:
- this, for method chaining
-
withPlaceholder
Sets the placeholder of this field. Ignored if the component does not support placeholders.- Parameters:
placeholder- the placeholder to set- Returns:
- this, for method chaining
-
withHelperText
Sets the helper text of this field. Ignored if the component does not support helper texts.- Parameters:
helperText- the helper text to set- Returns:
- this, for method chaining
-
asRequired
Makes this field required, showing the given message when it is empty.- Parameters:
errorMessage- the error message to show when the field is empty, notnull- Returns:
- this, for method chaining
- Throws:
NullPointerException- iferrorMessageisnull
-
withValidator
Adds a validator to this field. Validators run on the presentation value, in the order they were added and in addition to any Bean Validation annotations on the property. The validator presentation type must match the value type of the field component.- Parameters:
validator- the validator to add, notnull- Returns:
- this, for method chaining
- Throws:
NullPointerException- ifvalidatorisnull
-
withConverter
Sets a converter that adapts the presentation value of the component to the model type of the bean property (e.g. aStringfield bound to anIntegerproperty). The converter presentation type must match the value type of the field component: if the auto-generated component does not match, also set one viawithComponent(C).- Type Parameters:
P- the model (property) type- Parameters:
converter- the converter to use, notnull- Returns:
- this, for method chaining
- Throws:
NullPointerException- ifconverterisnull
-
withComponent
Replaces the auto-generated component of this field with the given one, and types this wrapper after the value type of the new component.A component whose value type differs from the property type needs a converter, which is set afterwards on the returned wrapper:
The two are therefore not validated here, but when the form first interacts with a bean, throughform.configureField("age").withComponent(new TextField()) .withConverter(new StringToIntegerConverter("Must be a number"));EasyForm.setBean(Object),EasyForm.readBean(Object)orEasyForm.getValidBean().- Type Parameters:
W- the presentation value type of the given componentC- the component type, which must be aComponentand aHasValueof the presentation value type- Parameters:
component- the component to use, notnull- Returns:
- this, for method chaining
- Throws:
NullPointerException- ifcomponentisnull
-
withColSpan
Sets the number of columns this field spans in the form layout. Defaults to 1.- Parameters:
colSpan- the column span, at least 1- Returns:
- this, for method chaining
- Throws:
IllegalArgumentException- if the given span is less than 1
-