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
Enclosing class:
EasyForm<T>

public static final class EasyForm.Field<V> extends Object implements 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 Details

    • visible

      public EasyForm.Field<V> visible()
      Makes this field visible and editable (the default state), reversing readOnly() or excluded().
      Returns:
      this, for method chaining
    • readOnly

      public EasyForm.Field<V> readOnly()
      Makes this field read-only: it is displayed and populated from the bean, but cannot be edited.
      Returns:
      this, for method chaining
    • excluded

      public EasyForm.Field<V> 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 with visible().
      Returns:
      this, for method chaining
    • withLabel

      public EasyForm.Field<V> withLabel(String label)
      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

      public EasyForm.Field<V> withPlaceholder(String placeholder)
      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

      public EasyForm.Field<V> withHelperText(String helperText)
      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

      public EasyForm.Field<V> asRequired(String errorMessage)
      Makes this field required, showing the given message when it is empty.
      Parameters:
      errorMessage - the error message to show when the field is empty, not null
      Returns:
      this, for method chaining
      Throws:
      NullPointerException - if errorMessage is null
    • withValidator

      public EasyForm.Field<V> withValidator(Validator<V> validator)
      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, not null
      Returns:
      this, for method chaining
      Throws:
      NullPointerException - if validator is null
    • withConverter

      public <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. a String field bound to an Integer property). The converter presentation type must match the value type of the field component: if the auto-generated component does not match, also set one via withComponent(C).
      Type Parameters:
      P - the model (property) type
      Parameters:
      converter - the converter to use, not null
      Returns:
      this, for method chaining
      Throws:
      NullPointerException - if converter is null
    • withComponent

      public <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.

      A component whose value type differs from the property type needs a converter, which is set afterwards on the returned wrapper:

      
       form.configureField("age").withComponent(new TextField())
           .withConverter(new StringToIntegerConverter("Must be a number"));
       
      The two are therefore not validated here, but when the form first interacts with a bean, through EasyForm.setBean(Object), EasyForm.readBean(Object) or EasyForm.getValidBean().
      Type Parameters:
      W - the presentation value type of the given component
      C - the component type, which must be a Component and a HasValue of the presentation value type
      Parameters:
      component - the component to use, not null
      Returns:
      this, for method chaining
      Throws:
      NullPointerException - if component is null
    • withColSpan

      public EasyForm.Field<V> withColSpan(int colSpan)
      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