Package com.storedobject.vaadin
Class AbstractDataForm<D>
java.lang.Object
com.storedobject.vaadin.View
com.storedobject.vaadin.AbstractDataForm<D>
- Type Parameters:
D- Type of data in the embedded form
- All Implemented Interfaces:
ClickHandler,ExecutableView,HasContainer,ValueChangeHandler,com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<? extends com.vaadin.flow.component.Component>>,com.vaadin.flow.component.HasValue.ValueChangeListener,Serializable,Runnable,EventListener
- Direct Known Subclasses:
AbstractDataEditor,DataForm,TemplateDataForm
A view that is used for creating "data entry forms". An
AbstractForm is embedded in the view.- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classFor internal use only.Nested classes/interfaces inherited from interface com.storedobject.vaadin.ClickHandler
ClickHandler.ModifiedClickEvent<C extends com.vaadin.flow.component.Component> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(com.vaadin.flow.component.Component... components) Add components to the form's field container.com.vaadin.flow.shared.RegistrationaddConstructedListener(ConstructedListener constructedListener) Add aConstructedListenerso that we will be informed about when the UI part is constructed.voidaddField(com.vaadin.flow.component.HasValue<?, ?>... fields) Add fields to the form.voidAdd a field to the form.com.vaadin.flow.shared.RegistrationaddIncludeFieldChecker(IncludeField includeField) Add an "include field checker" to the existing chain.<T> voidaddValidator(com.vaadin.flow.component.HasValue<?, T> field, Function<T, Boolean> validator) Add a validator for the field.<T> voidaddValidator(com.vaadin.flow.component.HasValue<?, T> field, Function<T, Boolean> validator, String errorMessage) Add a validator for the field.protected voidattachField(String fieldName, com.vaadin.flow.component.HasValue<?, ?> field) Attach a field to the form.voidclean()Close resources if any that are left opened.voidClear all alters owned by this view.static voidclearError(com.vaadin.flow.component.HasValue<?, ?> field) Clear the error status associated with a field.voidClear error status of all the fields.voidClear values of all the fields.booleancommit()Save data from the fields to the internal data structure.booleanconnect(com.vaadin.flow.component.HasValue<?, ?>... fields) Connect fields so that a change in any of it is propagated to others within that connected group.booleanConnect fields so that a change in any of it is propagated to others within that connected group.booleanconnect(Collection<com.vaadin.flow.component.HasValue<?, ?>> fields) Connect fields so that a change in any of it is propagated to others within that connected group.protected com.vaadin.flow.component.HasComponentsThis method is invoked to create a "button panel" to be displayed typically at the top of the view's layout.protected com.vaadin.flow.component.HasValue<?, ?> createField(String fieldName) Create the field for a particular "field name".protected com.vaadin.flow.component.HasValue<?, ?> createField(String fieldName, String label) Create the field for a particular "field name".protected com.vaadin.flow.component.HasComponentsCreate the field container of this form.protected com.vaadin.flow.component.HasComponentsThis method is invoked to create the layout of the view.protected voiddetachField(String fieldName, com.vaadin.flow.component.HasValue<?, ?> field) Detach a field from the form.protected voidfieldAttached(String fieldName, com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked whenever a field is attached to the form.protected voidfieldDetached(String fieldName, com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked whenever a field is detached from the form.protected final voidThis method is invoked to inform allConstructedListeners when the form is constructed.protected voidThis method is invoked when the form is constructed.final intGet number of responsive columns for the form.intgetColumnSpan(com.vaadin.flow.component.Component component) Get the column span of a component.com.vaadin.flow.component.HasComponentsGet the field container of the form.com.vaadin.flow.component.ComponentGet the field container of the form as a component.getData()Get the "data" associated with the form.com.vaadin.flow.component.HasTextGet the current error display of the form.com.vaadin.flow.component.HasValue<?, ?> Get a field associated with a field name.final StringgetFieldLabel(com.vaadin.flow.component.HasValue<?, ?> field) Get label for the given field.final StringgetFieldLabel(String fieldName) Get label for the given field.getFieldName(com.vaadin.flow.component.HasValue<?, ?> field) Get a field name associated with a field.Get the field names.getForm()Get the form embedded in this view.protected StringThis method is invoked to determine the label used for displaying the field.booleanisFieldEditable(com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked to determine if a field needs to be made editable or not.booleanisFieldEditable(String fieldName) This method is invoked to determine if a field needs to be made editable or not.booleanisFieldVisible(com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked to determine if a field needs to be made visible or not.booleanisFieldVisible(String fieldName) This method is invoked to determine if a field needs to be made visible or not.booleanCheck whether the view is "read only" or not.voidload()Load data to the fields from the internal data structure.static voidmarkError(com.vaadin.flow.component.HasValue<?, ?> field) Mark a field as not valid.voidnewLine()Add a new line to the form.voidremove(com.vaadin.flow.component.Component... components) Remove components from the form's field container.voidRemove all components from the form's field container.voidremoveField(com.vaadin.flow.component.HasValue<?, ?> field) Remove a field from the form.voidremoveField(String fieldName) Remove a field from the form.voidremoveField(String... fieldNames) Remove fields from the form.voidsetColumns(int columns) Set number of responsive columns for the form.voidsetColumnSpan(com.vaadin.flow.component.Component component, int columnSpan) Set number of columns to span for a particular component.voidsetErrorDisplay(com.vaadin.flow.component.HasText display) Error messages of the form are typically displayed usingNotification.voidsetFieldContainerProvider(HasContainer fieldContainerProvider) Set the field container provider for this form so thatcreateFieldContainer()} can provide the component container from this.voidsetFieldCustomizer(FieldCustomizer fieldCustomizer) Set an external field customizer.voidsetFieldEditable(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields editable.voidsetFieldEditable(String... fieldNames) Set fields editable.voidsetFieldHidden(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields hidden.voidsetFieldHidden(String... fieldNames) Set fields hidden.final voidsetFieldLabel(com.vaadin.flow.component.HasValue<?, ?> field, String label) Set label for a specific field.final voidsetFieldLabel(String fieldName, String label) Set label for a specific field.voidsetFieldReadOnly(boolean readOnly, com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields read only.voidsetFieldReadOnly(boolean readOnly, String... fieldNames) Set fields read only.voidsetFieldReadOnly(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields read only.voidsetFieldReadOnly(String... fieldNames) Set fields read only.voidsetFieldVisible(boolean visible, com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields visible.voidsetFieldVisible(boolean visible, String... fieldNames) Set fields visible.voidsetFieldVisible(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields visible.voidsetFieldVisible(String... fieldNames) Set fields visible.voidsetIncludeFieldChecker(IncludeField includeField) Set "include field checker".voidsetReadOnly(boolean readOnly) Set the view read only.voidsetRequired(com.vaadin.flow.component.HasValue<?, ?> field) Set the "required" attribute of a field.voidsetRequired(com.vaadin.flow.component.HasValue<?, ?>... fields) Sets the specified fields as required in the form.voidsetRequired(com.vaadin.flow.component.HasValue<?, ?> field, boolean required) Set the "required" attribute of a field.voidsetRequired(com.vaadin.flow.component.HasValue<?, ?> field, boolean required, String errorMessage) Set the "required" attribute of a field.voidsetRequired(com.vaadin.flow.component.HasValue<?, ?> field, String errorMessage) Set the "required" attribute of a field.voidsetRequired(String fieldName) Set the "required" attribute of a field.voidsetRequired(String fieldName, boolean required) Set the "required" attribute of a field.voidsetRequired(String fieldName, boolean required, String errorMessage) Set the "required" attribute of a field.voidsetRequired(String fieldName, String errorMessage) Set the "required" attribute of a field.Get all fields names.final Stream<com.vaadin.flow.component.HasValue<?, ?>> Get all fields.Methods inherited from class com.storedobject.vaadin.View
abort, aborted, addClosedListener, addOpenedListener, close, createCloseableView, createWindow, decorateComponent, execute, execute, execute, executing, focus, focus, focusAny, getApplication, getCaption, getComponent, getCreatedBy, getEmbeddedView, getMenuItem, getMenuItem, getView, initUI, invoke, isFullScreen, isScrollable, isWindowMode, select, setCaption, setComponent, setCreatedBy, setDefaultPadding, setEmbeddedView, setFirstFocus, setFullScreen, setScrollable, setWindowMode, skipFirstFocusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.storedobject.vaadin.ClickHandler
clicked, doubleClicked, onComponentEvent, rightClickedMethods inherited from interface com.storedobject.vaadin.ExecutableView
clicked, createMenuItem, error, getMenuIconName, getView, isCloseable, isHomeView, log, log, message, returnedFrom, run, setClickable, speak, trackValueChange, tray, valueChanged, warningMethods inherited from interface com.storedobject.vaadin.ValueChangeHandler
valueChanged
-
Field Details
-
form
Form embedded in this view.
-
-
Constructor Details
-
AbstractDataForm
public AbstractDataForm()
-
-
Method Details
-
getForm
-
formConstructed
protected void formConstructed()This method is invoked when the form is constructed. -
fireFormConstructed
protected final void fireFormConstructed()This method is invoked to inform allConstructedListeners when the form is constructed. -
addConstructedListener
public com.vaadin.flow.shared.Registration addConstructedListener(ConstructedListener constructedListener) Add aConstructedListenerso that we will be informed about when the UI part is constructed.- Parameters:
constructedListener- Listener.- Returns:
- Registration.
-
getData
-
getContent
public com.vaadin.flow.component.Component getContent()Get the field container of the form as a component.- Overrides:
getContentin classView- Returns:
- Field container as a component.
nullis returned if the field container is not a component.
-
setFieldContainerProvider
Set the field container provider for this form so thatcreateFieldContainer()} can provide the component container from this.- Parameters:
fieldContainerProvider- Field container to set
-
createFieldContainer
protected com.vaadin.flow.component.HasComponents createFieldContainer()Create the field container of this form. Default implementation creates a container from the field container provider that was set, otherwise, it createsFormLayout.- Returns:
- Field container created.
-
createLayout
protected com.vaadin.flow.component.HasComponents createLayout()This method is invoked to create the layout of the view.- Returns:
- Layout
-
createButtonLayout
protected com.vaadin.flow.component.HasComponents createButtonLayout()This method is invoked to create a "button panel" to be displayed typically at the top of the view's layout.- Returns:
- A component to display other components, typically, buttons.
-
getContainer
public com.vaadin.flow.component.HasComponents getContainer()Get the field container of the form.- Specified by:
getContainerin interfaceHasContainer- Returns:
- Field container.
-
getFieldNames
-
setIncludeFieldChecker
Set "include field checker". It will determine if a field can be added or not.- Parameters:
includeField- The "include field checker"
-
addIncludeFieldChecker
Add an "include field checker" to the existing chain. If any one of theIncludeFieldin the chain returnsfalsefor a specific field, the field will not be included in the form.- Parameters:
includeField- The "include field checker" to add.- Returns:
- Registration.
-
setFieldCustomizer
Set an external field customizer. If set, the methodFieldCustomizer.customizeField(String, HasValue)will be invoked when each field gets created.- Parameters:
fieldCustomizer- Field customizer.
-
createField
Create the field for a particular "field name".- Parameters:
fieldName- Field name- Returns:
- Field created.
-
createField
-
addField
public void addField(com.vaadin.flow.component.HasValue<?, ?>... fields) Add fields to the form. These fields will not be having "field names".- Parameters:
fields- Fields to be added
-
addField
Add a field to the form.- Parameters:
fieldName- Name associated with the fieldfield- Field
-
removeField
Remove a field from the form.- Parameters:
fieldName- Name of the field to be removed.
-
removeField
Remove fields from the form.- Parameters:
fieldNames- Names of the field to be removed
-
removeField
public void removeField(com.vaadin.flow.component.HasValue<?, ?> field) Remove a field from the form.- Parameters:
field- Field to be removed.
-
add
public void add(com.vaadin.flow.component.Component... components) Add components to the form's field container.- Parameters:
components- Components to add
-
remove
public void remove(com.vaadin.flow.component.Component... components) Remove components from the form's field container.- Parameters:
components- Components to remove
-
removeAll
public void removeAll()Remove all components from the form's field container. -
load
public void load()Load data to the fields from the internal data structure. -
commit
public boolean commit()Save data from the fields to the internal data structure.- Returns:
- True if data is saved successfully.
-
getField
Get a field associated with a field name.- Parameters:
fieldName- Name of the field- Returns:
- Field.
-
getFieldName
Get a field name associated with a field.- Parameters:
field- Field- Returns:
- Name of the field.
-
setRequired
public void setRequired(com.vaadin.flow.component.HasValue<?, ?>... fields) Sets the specified fields as required in the form.- Parameters:
fields- the array of fields to be marked as required; each field in this array should implement the HasValue interface. Null values and fields within the array will be ignored.
-
setRequired
public void setRequired(com.vaadin.flow.component.HasValue<?, ?> field) Set the "required" attribute of a field. If set to true, with empty data (checked by invokingHasValue.isEmpty()),commit()will fail.- Parameters:
field- Field
-
setRequired
-
setRequired
Set the "required" attribute of a field. If set to true, with empty data (checked by invokingHasValue.isEmpty()),commit()will fail.- Parameters:
field- FielderrorMessage- Error message to show when the field is empty
-
setRequired
-
setRequired
public void setRequired(com.vaadin.flow.component.HasValue<?, ?> field, boolean required) Set the "required" attribute of a field. If set to true, with empty data (checked by invokingHasValue.isEmpty()),commit()will fail.- Parameters:
field- Fieldrequired- True or false
-
setRequired
-
setRequired
public void setRequired(com.vaadin.flow.component.HasValue<?, ?> field, boolean required, String errorMessage) Set the "required" attribute of a field. If set to true, with empty data (checked by invokingHasValue.isEmpty()),commit()will fail.- Parameters:
field- Fieldrequired- True or falseerrorMessage- Error message to show when the field is empty
-
setRequired
Set the "required" attribute of a field. If set to true, with empty data (checked by invokingHasValue.isEmpty()),commit()will fail.- Parameters:
fieldName- Field namerequired- True or falseerrorMessage- Error message to show when the field is empty
-
addValidator
-
addValidator
public <T> void addValidator(com.vaadin.flow.component.HasValue<?, T> field, Function<T, Boolean> validator, String errorMessage) Add a validator for the field. Validator should returntrueif the field is valid.- Type Parameters:
T- Type of the field value.- Parameters:
field- Fieldvalidator- ValidatorerrorMessage- Error message to be displayed if the field is not valid
-
markError
public static void markError(com.vaadin.flow.component.HasValue<?, ?> field) Mark a field as not valid.- Parameters:
field- Field
-
clearError
public static void clearError(com.vaadin.flow.component.HasValue<?, ?> field) Clear the error status associated with a field.- Parameters:
field- Field
-
clearFields
public void clearFields()Clear values of all the fields. -
clearErrors
public void clearErrors()Clear error status of all the fields. -
setReadOnly
public void setReadOnly(boolean readOnly) Set the view read only.- Parameters:
readOnly- True or false
-
isReadOnly
public boolean isReadOnly()Check whether the view is "read only" or not.- Returns:
- True or false.
-
isFieldVisible
This method is invoked to determine if a field needs to be made visible or not.- Parameters:
fieldName- Name of the field- Returns:
- True or false.
-
isFieldVisible
public boolean isFieldVisible(com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked to determine if a field needs to be made visible or not.- Parameters:
field- Field- Returns:
- True or false.
-
setFieldVisible
Set fields visible. (By default fields are visible).- Parameters:
fieldNames- Field names
-
setFieldVisible
public void setFieldVisible(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields visible. (By default fields are visible).- Parameters:
fields- Fields
-
setFieldVisible
Set fields visible. (By default fields are visible).- Parameters:
visible- To make it visible or notfieldNames- Field names
-
setFieldVisible
public void setFieldVisible(boolean visible, com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields visible. (By default fields are visible).- Parameters:
visible- To make it visible or notfields- Fields
-
setFieldHidden
Set fields hidden. (By default fields are visible).- Parameters:
fieldNames- Field names
-
setFieldHidden
public void setFieldHidden(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields hidden. (By default fields are visible).- Parameters:
fields- Fields
-
isFieldEditable
This method is invoked to determine if a field needs to be made editable or not.- Parameters:
fieldName- Name of the field- Returns:
- True or false.
-
isFieldEditable
public boolean isFieldEditable(com.vaadin.flow.component.HasValue<?, ?> field) This method is invoked to determine if a field needs to be made editable or not.- Parameters:
field- Field- Returns:
- True or false.
-
setFieldEditable
Set fields editable. (By default fields are editable).- Parameters:
fieldNames- Field names
-
setFieldEditable
public void setFieldEditable(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields editable. (By default fields are editable).- Parameters:
fields- Fields
-
setFieldReadOnly
Set fields read only. (By default fields are editable).- Parameters:
fieldNames- Field names
-
setFieldReadOnly
public void setFieldReadOnly(com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields read only. (By default fields are editable).- Parameters:
fields- Fields
-
setFieldReadOnly
Set fields read only. (By default fields are editable).- Parameters:
readOnly- Read-only or not.fieldNames- Field names
-
setFieldReadOnly
public void setFieldReadOnly(boolean readOnly, com.vaadin.flow.component.HasValue<?, ?>... fields) Set fields read only. (By default fields are editable).- Parameters:
readOnly- Read-only or not.fields- Fields
-
getLabel
This method is invoked to determine the label used for displaying the field. The default implementation determine it by invokingApplicationEnvironment.createLabel(String).- Parameters:
fieldName- Name of the field- Returns:
- Label
-
setFieldLabel
-
setFieldLabel
Set label for a specific field. Label will be set only if the field has a setLabel(String) method.- Parameters:
field- Field for which label needs to be setlabel- Label to set
-
getFieldLabel
-
getFieldLabel
Get label for the given field.- Parameters:
field- Field- Returns:
- Label string if "getLabel" method exists in the field, otherwise null.
-
attachField
Attach a field to the form. This is invoked whenever a field is added to the form. The default implementation adds the component of the field (if it is a component) to the field container.- Parameters:
fieldName- Name of the fieldfield- Field
-
fieldAttached
This method is invoked whenever a field is attached to the form.- Parameters:
fieldName- Name of the fieldfield- Field
-
detachField
Detach a field from the form. This is invoked whenever a field is removed to the form. The default implementation removes the component of the field (if it is a component) from the field container.- Parameters:
fieldName- Name of the fieldfield- Field
-
fieldDetached
This method is invoked whenever a field is detached from the form.- Parameters:
fieldName- Name of the fieldfield- Field
-
setErrorDisplay
public void setErrorDisplay(com.vaadin.flow.component.HasText display) Error messages of the form are typically displayed usingNotification. However, one can set anyHasTextfor that.- Parameters:
display- Error messages will be displayed on this
-
getErrorDisplay
public com.vaadin.flow.component.HasText getErrorDisplay()Get the current error display of the form. (SeesetErrorDisplay(HasText)).- Returns:
- Current error display.
-
setColumns
public void setColumns(int columns) Set number of responsive columns for the form.- Parameters:
columns- Number of responsive columns required
-
getColumns
public final int getColumns()Get number of responsive columns for the form.- Returns:
- Number of responsive columns of the form.
-
newLine
public void newLine()Add a new line to the form. -
setColumnSpan
public void setColumnSpan(com.vaadin.flow.component.Component component, int columnSpan) Set number of columns to span for a particular component.- Parameters:
component- Component for which column span to be setcolumnSpan- Number of columns to span
-
getColumnSpan
public int getColumnSpan(com.vaadin.flow.component.Component component) Get the column span of a component.- Parameters:
component- Component for which column span to be retrieved- Returns:
- Column span for the component.
-
connect
Connect fields so that a change in any of it is propagated to others within that connected group.- Parameters:
fieldNames- Fields to connect.- Returns:
- True if connection is established successfully.
-
connect
public boolean connect(com.vaadin.flow.component.HasValue<?, ?>... fields) Connect fields so that a change in any of it is propagated to others within that connected group.- Parameters:
fields- Fields to connect.- Returns:
- True if connection is established successfully.
-
connect
Connect fields so that a change in any of it is propagated to others within that connected group.- Parameters:
fields- Fields to connect.- Returns:
- True if connection is established successfully.
-
clean
public void clean()Description copied from class:ViewClose resources if any that are left opened. This method is invoked when the view is removed from theApplication. The default implementation does nothing.- Specified by:
cleanin interfaceExecutableView- Overrides:
cleanin classView
-
streamFieldsCreated
Get all fields.- Returns:
- Stream of fields.
-
streamFieldNamesCreated
-
clearAlerts
public void clearAlerts()Description copied from interface:ExecutableViewClear all alters owned by this view.- Specified by:
clearAlertsin interfaceExecutableView
-