Composite Fields with CustomField

    A composite field class must implement the getType() and initContent() methods. The latter should return the content composite of the field. It is typically a layout component, but can be any component.

    It is also possible to override validate(), setInternalValue(), commit(), setPropertyDataSource, isEmpty() and other methods to implement different functionalities in the field. Methods overriding setInternalValue() should call the superclass method.

    A custom switch button field

    Java

    We can now use the field in all the normal ways for a field:

    1. BooleanField field = new BooleanField();
    2. // ...and read the value
    3. Label value = new Label(field.getValue()?
    4. // ...and handle value changes
    5. field.addValueChangeListener(event ->