Class BeanValidationForm<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div>
org.vaadin.firitin.form.BeanValidationForm<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

@Deprecated(forRemoval=false) public abstract class BeanValidationForm<T> extends com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div>
Deprecated.
handle with care, very little tested and should be considered experimental at this point. API will most likely change, but feedback is more than welcome.
This is "the next version" of the AbstractForm class, that finally, since V7 era, works properly with e.g. cross field validation and validation groups.

This version uses FormBinder (published in Viritin 2.8) instead of the basic Vaadin Binder. This might already be better, but most likely there are regressions and edge case that may be incompatible with the old AbstractForm, thus bringing in this with a different name for testing. Once tested enough and if no big regressions, AbstractForm becomes this and possible a backwards compatibility version is created for "core Binder version".

In the default configuration BeanValidationForm expects that fields are lazily pushing their value change events to the server. This way it can automatically adjust e.g. save/cancel buttons based on the state/validity. Either use Viritin fields like VTextField or configure e.g. with setValueChangeMode.

Author:
mstahv
See Also:
  • Constructor Details Link icon

    • BeanValidationForm Link icon

      public BeanValidationForm(Class<T> entityType)
      Deprecated.
      Constructor for the abstract form.
      Parameters:
      entityType - The class type used for data binding
  • Method Details Link icon

    • setEntityWithEnabledSave Link icon

      public void setEntityWithEnabledSave(T entity)
      Deprecated.
      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 Link icon

      public boolean hasChanges()
      Deprecated.
      Returns:
      true if bean has been changed since last setEntity call.
    • setHasChanges Link icon

      protected void setHasChanges(boolean hasChanges)
      Deprecated.
    • isValid Link icon

      @Deprecated public boolean isValid()
      Deprecated.
    • getResetHandler Link icon

      public BeanValidationForm.ResetHandler<T> getResetHandler()
      Deprecated.
    • setResetHandler Link icon

      public void setResetHandler(BeanValidationForm.ResetHandler<T> resetHandler)
      Deprecated.
    • getSavedHandler Link icon

      public BeanValidationForm.SavedHandler<T> getSavedHandler()
      Deprecated.
    • setSavedHandler Link icon

      public void setSavedHandler(BeanValidationForm.SavedHandler<T> savedHandler)
      Deprecated.
    • getDeleteHandler Link icon

      public BeanValidationForm.DeleteHandler<T> getDeleteHandler()
      Deprecated.
    • setDeleteHandler Link icon

      public void setDeleteHandler(BeanValidationForm.DeleteHandler<T> deleteHandler)
      Deprecated.
    • getSaveCaption Link icon

      public String getSaveCaption()
      Deprecated.
    • setSaveCaption Link icon

      public void setSaveCaption(String saveCaption)
      Deprecated.
    • getModalWindowTitle Link icon

      public String getModalWindowTitle()
      Deprecated.
    • setModalWindowTitle Link icon

      public void setModalWindowTitle(String modalWindowTitle)
      Deprecated.
    • getDeleteCaption Link icon

      public String getDeleteCaption()
      Deprecated.
    • setDeleteCaption Link icon

      public void setDeleteCaption(String deleteCaption)
      Deprecated.
    • getCancelCaption Link icon

      public String getCancelCaption()
      Deprecated.
    • setCancelCaption Link icon

      public void setCancelCaption(String cancelCaption)
      Deprecated.
    • getBinder Link icon

      public FormBinder<T> getBinder()
      Deprecated.
    • lazyInit Link icon

      protected void lazyInit()
      Deprecated.
    • bind Link icon

      protected void bind()
      Deprecated.
    • getValidationGroups Link icon

      public Class<?>[] getValidationGroups()
      Deprecated.
    • setValidationGroups Link icon

      public void setValidationGroups(Class<?>... groups)
      Deprecated.
    • doBeanValidation Link icon

      protected <T> Set<jakarta.validation.ConstraintViolation<T>> doBeanValidation(T object)
      Deprecated.
    • getValidator Link icon

      protected jakarta.validation.Validator getValidator()
      Deprecated.
    • createContent Link icon

      protected com.vaadin.flow.component.Component createContent()
      Deprecated.
      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
    • getFormLayout Link icon

      protected com.vaadin.flow.component.HasComponents getFormLayout()
      Deprecated.
    • getClassLevelViolationsDisplay Link icon

      public com.vaadin.flow.component.Component getClassLevelViolationsDisplay()
      Deprecated.
    • setClassLevelViolationsDisplay Link icon

      public void setClassLevelViolationsDisplay(com.vaadin.flow.component.HasComponents classLevelViolationsDisplay)
      Deprecated.
    • getFormComponents Link icon

      protected abstract List<com.vaadin.flow.component.Component> getFormComponents()
      Deprecated.
      Return the list of field components added to the form body by default. Use a dummy implementation if your override createContent() method where you can fully customise how the content of the form is built.
      Returns:
      the fields displayed in the form created by createContent() method.
    • adjustSaveButtonState Link icon

      protected void adjustSaveButtonState()
      Deprecated.
      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 Link icon

      public com.vaadin.flow.component.button.Button getSaveButton()
      Deprecated.
    • setSaveButton Link icon

      public void setSaveButton(com.vaadin.flow.component.button.Button button)
      Deprecated.
    • createSaveButton Link icon

      protected com.vaadin.flow.component.button.Button createSaveButton()
      Deprecated.
    • isBound Link icon

      protected boolean isBound()
      Deprecated.
    • createResetButton Link icon

      protected com.vaadin.flow.component.button.Button createResetButton()
      Deprecated.
    • getResetButton Link icon

      public com.vaadin.flow.component.button.Button getResetButton()
      Deprecated.
    • setResetButton Link icon

      public void setResetButton(com.vaadin.flow.component.button.Button resetButton)
      Deprecated.
    • createDeleteButton Link icon

      protected com.vaadin.flow.component.button.Button createDeleteButton()
      Deprecated.
    • getDeleteButton Link icon

      public com.vaadin.flow.component.button.Button getDeleteButton()
      Deprecated.
    • setDeleteButton Link icon

      public void setDeleteButton(com.vaadin.flow.component.button.Button deleteButton)
      Deprecated.
    • adjustResetButtonState Link icon

      protected void adjustResetButtonState()
      Deprecated.
      Adjusts the reset button state. Override if you for example wish to keep reset/cancel button enabled even if there is nothing to reset.
    • getEntity Link icon

      public T getEntity()
      Deprecated.
      Returns:
      the currently edited entity or null if the form is currently unbound
    • setEntity Link icon

      public void setEntity(T entity)
      Deprecated.
      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
    • save Link icon

      protected void save(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
      Deprecated.
    • reset Link icon

      protected void reset(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
      Deprecated.
    • delete Link icon

      protected void delete(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> e)
      Deprecated.
    • getToolbar Link icon

      public com.vaadin.flow.component.orderedlayout.HorizontalLayout getToolbar()
      Deprecated.
      Returns:
      A default toolbar containing save/cancel/delete buttons
    • openInModalPopup Link icon

      public VDialog openInModalPopup()
      Deprecated.
    • focusFirst Link icon

      public void focusFirst()
      Deprecated.
      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 Link icon

      public com.vaadin.flow.component.dialog.Dialog getPopup()
      Deprecated.
      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 Link icon

      public void closePopup()
      Deprecated.