Class Output<T extends Output<T>>


public class Output<T extends Output<T>> extends StyledContainerElement<T>
Represents an HTML <output> element that displays the result of a calculation or user action.

The <output> element is used to represent the result of a calculation performed by the browser or a script, typically within a form context. It's commonly used to display computed values, calculation results, or the outcome of form interactions in real-time.

Features:

  • Displays calculation results and computed values
  • Can reference the elements used in the calculation
  • Associates with a form element
  • Named for form submission and scripting access
  • Semantic representation of output values
  • Supports dynamic content updates via JavaScript

Usage:


 // Simple calculator output
 Form calculator = new Form();

 Input num1 = new Input();
 num1.setId("number1");
 num1.setType(InputType.NUMBER);
 calculator.addElement(num1);

 Input num2 = new Input();
 num2.setId("number2");
 num2.setType(InputType.NUMBER);
 calculator.addElement(num2);

 Output result = new Output();
 result.setFor("number1 number2");
 result.setName("sum");
 result.addText("0");
 calculator.addElement(result);

 // Range slider with output display
 Input range = new Input();
 range.setId("volume");
 range.setType(InputType.RANGE);
 range.setMin(0);
 range.setMax(100);

 Output volumeDisplay = new Output();
 volumeDisplay.setFor("volume");
 volumeDisplay.setName("volumeLevel");
 volumeDisplay.addText("50");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Output

      public Output()
      Constructs a new Output element.

      Creates an HTML <output> element ready to display calculation results or computed values.

  • Method Details

    • setFor

      public final T setFor(String elementId)
      Sets the element IDs that contribute to this output's value.

      The for attribute specifies a space-separated list of element IDs whose values are used to calculate or produce this output. This creates a relationship between the input elements and the output element, which is important for accessibility and semantic meaning.

      Parameters:
      elementId - space-separated list of element IDs (e.g., "input1 input2")
      Returns:
      this element for method chaining
    • setForm

      public final T setForm(String formId)
      Associates this element with a form element.

      Specifies the form this element belongs to using the form's ID. This is useful when the element is placed outside of its associated <form> in the document.

      Parameters:
      formId - the ID of the form element to associate with
      Returns:
      This element for method chaining.
    • setName

      public final T setName(String name)
      Sets the name attribute.

      Specifies the name of the element, used as a key when submitting form data or for programmatic access.

      Parameters:
      name - The name of the element.
      Returns:
      This element for method chaining.
    • setValue

      public final T setValue(String value)
      Sets the default value of this output element.
      Parameters:
      value - The value for this output.
      Returns:
      This element for method chaining.
    • getForm

      protected String getForm()
      Returns the form attribute value.

      The form attribute associates this element with a form element that is not its ancestor.

      Returns:
      The associated form ID, or null if not set.
    • setFormAction

      protected T setFormAction(String formAction)
      Sets the formaction attribute.

      Overrides the form's action attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image". The value specifies the URL to submit the form data to.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      formAction - The URL for form submission.
      Returns:
      This element for method chaining.
    • setFormEncType

      protected T setFormEncType(String formEncType)
      Sets the formenctype attribute.

      Overrides the form's enctype attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image".

      Parameters:
      formEncType - The encoding type for form submission.
      Returns:
      This element for method chaining.
    • setFormEncType

      protected T setFormEncType(FormEncoding formEncType)
      Sets the form encoding type override using the FormEncoding enum.
      Parameters:
      formEncType - The encoding type.
      Returns:
      This element for method chaining.
    • setFormMethod

      protected T setFormMethod(String formMethod)
      Sets the formmethod attribute.

      Overrides the form's method attribute for this specific submit button. Used on <button> and <input> elements with type="submit" or type="image".

      Parameters:
      formMethod - The HTTP method for form submission (get, post).
      Returns:
      This element for method chaining.
    • setFormMethod

      protected T setFormMethod(FormMethod formMethod)
      Sets the form method override using the FormMethod enum.
      Parameters:
      formMethod - The HTTP method (GET or POST).
      Returns:
      This element for method chaining.
    • setFormNoValidate

      protected T setFormNoValidate(boolean formNoValidate)
      Sets the formnovalidate boolean attribute.

      Overrides the form's validation behavior for this specific submit button, bypassing constraint validation. Used on <button> and <input> elements with type="submit" or type="image".

      Parameters:
      formNoValidate - True to skip form validation, false to remove.
      Returns:
      This element for method chaining.
    • setFormTarget

      protected T setFormTarget(String formTarget)
      Sets the formtarget attribute.

      Overrides the form's target attribute for this specific submit button, specifying where to display the response. Used on <button> and <input> elements with type="submit" or type="image". Values include "_self", "_blank", "_parent", and "_top".

      Parameters:
      formTarget - The browsing context for form submission.
      Returns:
      This element for method chaining.
    • setFormTarget

      protected T setFormTarget(Target formTarget)
      Sets the form target override using the Target enum.
      Parameters:
      formTarget - The browsing context for form submission.
      Returns:
      This element for method chaining.
    • getName

      protected String getName()
      Returns the name attribute value.

      The name attribute specifies the name used to identify the element in form submissions.

      Returns:
      The name, or null if not set.
    • getFormAction

      protected String getFormAction()
      Returns the formaction attribute value.

      The formaction attribute overrides the action attribute of the parent form for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements.

      Returns:
      The form action URL, or null if not set.
    • getFormEncType

      protected String getFormEncType()
      Returns the formenctype attribute value.

      The formenctype attribute overrides the enctype attribute of the parent form for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements.

      Returns:
      The form encoding type, or null if not set.
    • getFormMethod

      protected String getFormMethod()
      Returns the formmethod attribute value.

      The formmethod attribute overrides the method attribute of the parent form for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements. Values are "get", "post", or "dialog".

      Returns:
      The form method, or null if not set.
    • isFormNoValidate

      protected boolean isFormNoValidate()
      Returns whether the formnovalidate attribute is set.

      The formnovalidate attribute overrides the novalidate attribute of the parent form, bypassing constraint validation for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements.

      Returns:
      true if formnovalidate is present, false otherwise.
    • getFormTarget

      protected String getFormTarget()
      Returns the formtarget attribute value.

      The formtarget attribute overrides the target attribute of the parent form for this specific submit button. Used on <button type="submit"> and <input type="submit"> elements. Values include "_self", "_blank", "_parent", and "_top".

      Returns:
      The form target, or null if not set.