Class OorianForm<T extends OorianForm<T>>


public class OorianForm<T extends OorianForm<T>> extends StyledContainerElement<T>
An Oorian form component that integrates with the framework's event handling and validation system.

OorianForm renders a <form> element but intercepts browser submission, sending form data to the server via the Oorian event system (AJAX, SSE, or WebSocket depending on the page's communication mode). Unlike a standard HTML Form which performs a page navigation on submit, OorianForm submits asynchronously, allowing the page to remain loaded and receive updates.

OorianForm integrates with the Oorian validation framework, providing methods to register ValidatedInputs and FormValidators, validate fields on submission, and manage validation state.

Usage Example:


 OorianForm form = new OorianForm("loginForm");
 form.addElement(new TextInput("username"));
 form.addElement(new PasswordInput("password"));
 form.addElement(new SubmitButton("Login"));
 form.registerListener(this);
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • OorianForm

      public OorianForm()
      Creates a new OorianForm with Oorian's form submission handler configured.
    • OorianForm

      public OorianForm(String id)
      Creates a new OorianForm with the specified ID.
      Parameters:
      id - The unique identifier for this form element.
  • Method Details

    • registerListener

      public void registerListener(FormListener listener)
      Registers a listener for form submission events.
      Parameters:
      listener - The form event listener.
    • addValidatedInput

      public final T addValidatedInput(ValidatedInput<?> validatedInput)
      Registers a ValidatedInput with this form.

      The input's field name (from InputElement.getName()) is used as the key for building the ValidationContext during form validation.

      Parameters:
      validatedInput - The ValidatedInput to register.
      Returns:
      This form for method chaining.
    • removeValidatedInput

      public final T removeValidatedInput(String fieldName)
      Removes a ValidatedInput from this form by field name.
      Parameters:
      fieldName - The name of the field to remove.
      Returns:
      This form for method chaining.
    • addFormValidator

      public final T addFormValidator(FormValidator validator)
      Adds a form-level validator for cross-field validation.
      Parameters:
      validator - The FormValidator to add.
      Returns:
      This form for method chaining.
    • removeFormValidator

      public final T removeFormValidator(FormValidator validator)
      Removes a form-level validator.
      Parameters:
      validator - The FormValidator to remove.
      Returns:
      This form for method chaining.
    • validate

      public ValidationResult validate(Parameters parameters)
      Validates all fields using the provided parameters.

      This method builds a ValidationContext from the Parameters object and validates all registered ValidatedInputs and form-level validators.

      Parameters:
      parameters - The Parameters object containing field values.
      Returns:
      Combined ValidationResult from all validators.
    • validate

      @SafeVarargs protected final ValidationResult validate(Parameters parameters, Class<? extends ValidationGroup>... groups)
      Validates all fields using the provided parameters with specific validation groups.

      Only validators belonging to the specified groups (plus the Default group) will be run.

      Parameters:
      parameters - The Parameters object containing field values.
      groups - The validation groups to use.
      Returns:
      Combined ValidationResult from matching validators.
    • validate

      public ValidationResult validate()
      Validates all fields using their current input values.

      This method reads values directly from the registered InputElements and validates all ValidatedInputs and form-level validators.

      Returns:
      Combined ValidationResult from all validators.
    • validate

      public ValidationResult validate(FormEvent event)
      Validates all fields using a FormEvent's parameters.

      This method is intended to be called from a FormListener's onEvent method. It builds a ValidationContext from the FormEvent's parameters and validates all registered ValidatedInputs and form-level validators.

      Parameters:
      event - The FormEvent containing form submission parameters.
      Returns:
      Combined ValidationResult from all validators.
    • validate

      @SafeVarargs public final ValidationResult validate(FormEvent event, Class<? extends ValidationGroup>... groups)
      Validates all fields using a FormEvent's parameters with specific validation groups.

      Only validators belonging to the specified groups (plus the Default group) will be run.

      Parameters:
      event - The FormEvent containing form submission parameters.
      groups - The validation groups to use.
      Returns:
      Combined ValidationResult from matching validators.
    • validateForCreate

      public ValidationResult validateForCreate(FormEvent event)
      Validates all fields for the Create scenario.

      This is a convenience method that validates with the DefaultGroups.Create group.

      Parameters:
      event - The FormEvent containing form submission parameters.
      Returns:
      Combined ValidationResult from Create group validators.
    • validateForUpdate

      public ValidationResult validateForUpdate(FormEvent event)
      Validates all fields for the Update scenario.

      This is a convenience method that validates with the DefaultGroups.Update group.

      Parameters:
      event - The FormEvent containing form submission parameters.
      Returns:
      Combined ValidationResult from Update group validators.
    • validateForDraft

      public ValidationResult validateForDraft(FormEvent event)
      Validates all fields for the Draft scenario.

      This is a convenience method that validates with the DefaultGroups.Draft group.

      Parameters:
      event - The FormEvent containing form submission parameters.
      Returns:
      Combined ValidationResult from Draft group validators.
    • clearValidation

      public void clearValidation()
      Clears all validation states and error displays.
    • isFormValid

      public boolean isFormValid()
      Returns whether all fields are currently valid.

      This method checks the last validation result for each ValidatedInput. Returns true if no validated inputs have been registered.

      Returns:
      true if all fields are valid, false otherwise.
    • getValidatedInput

      public ValidatedInput<?> getValidatedInput(String fieldName)
      Returns the ValidatedInput for the specified field name.
      Parameters:
      fieldName - The name of the field.
      Returns:
      The ValidatedInput, or null if not found.
    • getValidatedInputs

      public List<ValidatedInput<?>> getValidatedInputs()
      Returns a list of all registered ValidatedInputs.
      Returns:
      List of ValidatedInput objects, or an empty list if none are registered.
    • getFormValidators

      public List<FormValidator> getFormValidators()
      Returns the list of form-level validators.
      Returns:
      List of FormValidator objects, or an empty list if none are registered.
    • submit

      public void submit()
      Submits the form programmatically by sending a FormSubmitCommand to the client.
    • onFormSubmit

      public void onFormSubmit()
      Hook method called when the form is submitted.

      Override this method to handle form submission events.

    • onSubmit

      public void onSubmit(Parameters parameters)
      Hook method called on form submission with form parameters.

      Called automatically before the FormEvent is dispatched. Override this method to process form data before event dispatch.

      Parameters:
      parameters - The submitted form parameters.