Class AbstractForm<T>
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasStyle
,Serializable
For binding this form uses naming conventions, so for each field of your edited entity, it searches similarly named Vaadin component from your class extending AbstractForm.
By default, BeanValidationBinder is used, so validators defined in your DTO or entity class are taken into account. Note that Vaadin don't currently support class level validators so that must be handled separately. Binding is always non-buffered variant, create a clone of your DTO if you mind that it might get changed even if user don't press the save button.
- Author:
- mstahv
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A handler called when the built-in delete button of the form is called.static interface
A handler called when the built-in reset/cancel button of the form is called.static interface
A handler called when the built-in save button of the form is called. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adjusts the reset button state.protected void
Adjust save button state.protected void
bind()
By default just does simple name based binding.void
protected abstract com.vaadin.flow.component.Component
This method should return the actual content of the form, including possible toolbar.protected com.vaadin.flow.component.button.Button
protected com.vaadin.flow.component.button.Button
protected com.vaadin.flow.component.button.Button
protected void
delete
(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) void
Focuses the first field found from the form.com.vaadin.flow.data.binder.Binder
<T> com.vaadin.flow.component.button.Button
com.vaadin.flow.component.dialog.Dialog
getPopup()
com.vaadin.flow.component.button.Button
com.vaadin.flow.component.button.Button
com.vaadin.flow.component.orderedlayout.HorizontalLayout
boolean
protected boolean
isBound()
boolean
isValid()
protected void
lazyInit()
protected void
reset
(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) protected void
save
(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) void
void
setCancelCaption
(String cancelCaption) void
setDeleteButton
(com.vaadin.flow.component.button.Button deleteButton) void
setDeleteCaption
(String deleteCaption) void
setDeleteHandler
(AbstractForm.DeleteHandler<T> deleteHandler) void
Sets the object to be edited by this form.void
setEntityWithEnabledSave
(T entity) by default only save button get's enabled when form has any changes
you can use this method in case the prefilled entity is already valid and save should be possible to press without any changes
if entity is not valid saveButton will stay disabled!protected void
setHasChanges
(boolean hasChanges) void
setModalWindowTitle
(String modalWindowTitle) void
setResetButton
(com.vaadin.flow.component.button.Button resetButton) void
setResetHandler
(AbstractForm.ResetHandler<T> resetHandler) void
setSaveButton
(com.vaadin.flow.component.button.Button button) void
setSaveCaption
(String saveCaption) void
setSavedHandler
(AbstractForm.SavedHandler<T> savedHandler) Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElement, initContent
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
AbstractForm
Constructor for the abstract form.- Parameters:
entityType
- The class type used for data binding
-
-
Method Details
-
setEntity
Sets the object to be edited by this form. This method binds all fields from this form to given objects.If your form needs to manually configure something based on the state of the edited object, you can override this method to do that either before the object is bound to fields or to do something after the bean binding.
- Parameters:
entity
- the object to be edited by this form
-
setEntityWithEnabledSave
by default only save button get's enabled when form has any changes
you can use this method in case the prefilled entity is already valid and save should be possible to press without any changes
if entity is not valid saveButton will stay disabled!- Parameters:
entity
- the object to be edited by this form
-
hasChanges
public boolean hasChanges()- Returns:
- true if bean has been changed since last setEntity call.
-
setHasChanges
protected void setHasChanges(boolean hasChanges) -
isValid
public boolean isValid() -
setSavedHandler
-
setResetHandler
-
setDeleteHandler
-
getResetHandler
-
getSavedHandler
-
getDeleteHandler
-
getSaveCaption
-
setSaveCaption
-
getModalWindowTitle
-
setModalWindowTitle
-
getDeleteCaption
-
setDeleteCaption
-
getCancelCaption
-
setCancelCaption
-
getBinder
-
setBinder
-
lazyInit
protected void lazyInit() -
bind
protected void bind()By default just does simple name based binding. Override this method to customize the binding. -
createContent
protected abstract com.vaadin.flow.component.Component createContent()This method should return the actual content of the form, including possible toolbar. Use setEntity(T entity) to fill in the data. Am example implementation could look like this:public class PersonForm extends AbstractForm<Person> { private TextField firstName = new MTextField("First Name"); private TextField lastName = new MTextField("Last Name"); @Override protected Component createContent() { return new MVerticalLayout( new FormLayout( firstName, lastName ), getToolbar() ); } }
- Returns:
- the content of the form
-
adjustSaveButtonState
protected void adjustSaveButtonState()Adjust save button state. Override if you for example want to have Save button always enabled, even if the Binder has not tracked any changes yet. -
getSaveButton
public com.vaadin.flow.component.button.Button getSaveButton() -
createSaveButton
protected com.vaadin.flow.component.button.Button createSaveButton() -
isBound
protected boolean isBound() -
createResetButton
protected com.vaadin.flow.component.button.Button createResetButton() -
getResetButton
public com.vaadin.flow.component.button.Button getResetButton() -
setResetButton
public void setResetButton(com.vaadin.flow.component.button.Button resetButton) -
createDeleteButton
protected com.vaadin.flow.component.button.Button createDeleteButton() -
setDeleteButton
public void setDeleteButton(com.vaadin.flow.component.button.Button deleteButton) -
getDeleteButton
public com.vaadin.flow.component.button.Button getDeleteButton() -
adjustResetButtonState
protected void adjustResetButtonState()Adjusts the reset button state. Override if you for example wish to keep reset/cancel button enabled even if there is nothing to reset. -
setSaveButton
public void setSaveButton(com.vaadin.flow.component.button.Button button) -
getEntity
- Returns:
- the currently edited entity or null if the form is currently unbound
-
save
protected void save(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) -
reset
protected void reset(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) -
delete
protected void delete(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e) -
getToolbar
public com.vaadin.flow.component.orderedlayout.HorizontalLayout getToolbar()- Returns:
- A default toolbar containing save/cancel/delete buttons
-
openInModalPopup
-
focusFirst
public void focusFirst()Focuses the first field found from the form. It often improves UX to call this method, or focus another field, when you assign a bean for editing. -
getPopup
public com.vaadin.flow.component.dialog.Dialog getPopup()- Returns:
- the last Popup into which the Form was opened with #openInModalPopup method or null if the form hasn't been use in window
-
closePopup
public void closePopup()
-