Class CmsForm

java.lang.Object
org.opencms.gwt.client.ui.input.form.CmsForm

public class CmsForm extends Object
This class acts as a container for form fields.

It is also responsible for collecting and validating the values of the form fields.

Since:
8.0.0
  • Field Details

  • Constructor Details

    • CmsForm

      Creates a new form with an existing form widget container.

      Parameters:
      panel - the form widget container
    • CmsForm

      public CmsForm(boolean initPanel)
      Creates a new form and optionally sets the form widget container to a simple form field panel.

      Parameters:
      initPanel - if true, initializes the form widget container
  • Method Details

    • addField

      public void addField(I_CmsFormField field, String initialValue)
      Adds a form field.

      Parameters:
      field - the field to add
      initialValue - the initial field value
    • addField

      public void addField(String fieldGroup, I_CmsFormField formField)
      Adds a form field to the form.

      Parameters:
      fieldGroup - the form field group key
      formField - the form field which should be added
    • addField

      public void addField(String fieldGroup, I_CmsFormField formField, String initialValue)
      Adds a form field to the form and sets its initial value.

      Parameters:
      fieldGroup - the form field group key
      formField - the form field which should be added
      initialValue - the initial value of the form field, or null if the field shouldn't have an initial value
    • addResetHandler

      public void addResetHandler(I_CmsFormResetHandler handler)
      Adds a new form reset handler to the form.

      Parameters:
      handler - the new form reset handler
    • collectValues

      Collects all values from the form fields.

      This method omits form fields whose values are null.

      Returns:
      a map of the form field values
    • getEditedFields

      Returns the set of names of fields which have been edited by the user in the current form.

      Returns:
      the set of names of fields edited by the user
    • getField

      Returns the form field with a given id.

      Parameters:
      id - the id of the form field
      Returns:
      the form field with the given id, or null if no field was found
    • getFields

      Returns a map of this form's field, indexed by their field name.

      Returns:
      a map of form fields
    • getGroups

      Returns the field group ids of the form.

      Returns:
      the field groups
    • getWidget

      Returns the form widget container.

      Returns:
      the form widget container
    • handleSubmit

      public void handleSubmit(I_CmsFormSubmitHandler handler)
      Passes this form's data to a form submit handler.

      Parameters:
      handler - the form submit handler
    • noFieldsInvalid

      public boolean noFieldsInvalid()
      Checks that no fields are invalid.

      Returns:
      true if no fields are invalid.
    • noFieldsInvalid

      public boolean noFieldsInvalid(Collection<I_CmsFormField> fields)
      Returns true if none of the fields in a collection are marked as invalid.

      Parameters:
      fields - the form fields
      Returns:
      true if none of the fields are invalid
    • removeGroup

      public void removeGroup(String group)
      Removes all fields for the given group.

      Parameters:
      group - the group for which the fields should be removed
    • render

      public void render()
      Renders all fields.

    • renderGroup

      public void renderGroup(String group)
      Renders the fields of the given group.

      Parameters:
      group - the field group
    • setFormHandler

      public void setFormHandler(I_CmsFormHandler handler)
      Sets the form handler for this form.

      Parameters:
      handler - the form handler
    • setValidatorClass

      public void setValidatorClass(String validatorClass)
      Sets the server-side form validator class to use.

      Parameters:
      validatorClass - the form validator class name
    • setWidget

      public void setWidget(A_CmsFormFieldPanel widget)
      Sets the form widget container.
      Parameters:
      widget - the form widget container
    • validateAllFields

      public void validateAllFields()
      Performs an initial validation of all form fields.

    • validateAndSubmit

      public void validateAndSubmit()
      Validates the form fields and submits their values if the validation was successful.

    • validateField

      public void validateField(I_CmsFormField field)
      Validates a single field.

      Parameters:
      field - the field to validate
    • createValidatorConfig

      Returns the configuration string for the server side form validator.

      Returns:
      the form validator configuration string
    • defaultHandleKeyPress

      protected void defaultHandleKeyPress(I_CmsFormField field, int keyCode)
      The default keypress event handling function for form fields.

      Parameters:
      field - the form field for which the event has been fired
      keyCode - the key code
    • defaultHandleValueChange

      protected void defaultHandleValueChange(I_CmsFormField field, String newValue, boolean inhibitValidation)
      Default handler for value change events of form fields.

      Parameters:
      field - the form field for which the event has been fired
      inhibitValidation - prevents validation of the edited field
      newValue - the new value
    • getFieldsByModelId

      Gets the fields with a given model id.

      Parameters:
      modelId - the model id
      Returns:
      the fields with the given model id
    • updateFieldValidationStatus

      protected void updateFieldValidationStatus(I_CmsFormField field, org.opencms.gwt.shared.CmsValidationResult result)
      Updates the field validation status.

      Parameters:
      field - the form field
      result - the validation result
    • updateFieldValidationStatus

      protected void updateFieldValidationStatus(String fieldId, org.opencms.gwt.shared.CmsValidationResult result)
      Applies a validation result to a form field.

      Parameters:
      fieldId - the field id to which the validation result should be applied
      result - the result of the validation operation
    • updateModelValidationStatus

      protected void updateModelValidationStatus(String modelId, org.opencms.gwt.shared.CmsValidationResult result)
      Updates the model validation status.

      Parameters:
      modelId - the model id
      result - the validation result