Class AbstractText

java.lang.Object
fc.web.forms.Field
fc.web.forms.AbstractText
Direct Known Subclasses:
MaxSizable, TextArea

public abstract class AbstractText extends Field
Represents a field that:
  1. returns one (1) string as their value. Contrast this with selects/with/multiple and radiogroups that may return a String[].
  2. In addition, the name of this field is always returned on a form submit by the browser (barring browser hacks etc). For example, if a text field is not filled out by the user, the browser still returns that text field (with no value). Contrast this with radio buttons that are not returned at all (not even their name) if the user does not select them.

Important note: the trimValues(boolean) method will by default trim whitespace from the beginning/end of user input. If the resulting string is empty (""), then it will be treated as if the user had not entered anything. (which is typically the desired behavior).

  • Method Details

    • setValueFromSubmit

      public void setValueFromSubmit(FormData fd, jakarta.servlet.http.HttpServletRequest req) throws SubmitHackedException
      Sets the value of the field from the submitted form data. Note, by default, it is assumed that all abstract text fields have different names in the html form. Mulitple fields with the same name are not supported. If there is more than one field with the same name (such as multiple text fields with the same name), then only 1 value will be saved (and the rest will be ignored) [This is one of - or perhaps the only - restriction of this form API; without it, things become too complex to manage].
      Specified by:
      setValueFromSubmit in class Field
      Parameters:
      fd - the form data object to store the value in
      Throws:
      SubmitHackedException
    • setValue

      public void setValue(String value)
      Sets the initial value of this text element to the specified string. If the specified value is null, then the initial value is set to "" (the empty string).
    • setValue

      public void setValue(FormData fd, String value)
      Sets the selected values for this select in the specified form data. This is useful for showing different initial values to each user (before the form has been submitted by that user).

      If the form has not been submitted, there is no form data object. A form data object should be manually created if needed for storing the value.

      Parameters:
      fd - the non-null form data used for rendering the form
      value - the value to be set
    • getValue

      public String getValue(FormData fd)
      Returns a string representing the value of this field or null if there is no current value. The names of Form fields like text and textarea are always sent back by the browser if the field is enabled. However if the values are empty, then this method will return null. For example, if the browser returned foo=<span class="invalid-tag">invalid input: '&amp;bar'</span>=baz, then foo will have a null value (even though the servlet api returns an empty string).
    • getStringValue

      Convenience method that returns the value of this field as a String. null values (ie which can happen when the field is disabled and no value sent by the browser) are returned as an empty string.
      Throws:
      NumberFormatException - if the value could not be returned as in integer.
    • getIntValue

      public int getIntValue(FormData fd)
      Convenience method that returns the value of this field as a Integer.
      Throws:
      NumberFormatException - if the value could not be returned as an integer.
    • getShortValue

      public short getShortValue(FormData fd)
      Convenience method that returns the value of this field as a Short.
      Throws:
      NumberFormatException - if the value could not be returned as a short.
    • getFloatValue

      public float getFloatValue(FormData fd)
      Convenience method that returns the value of this field as a Float.
      Throws:
      NumberFormatException - if the value could not be returned as a float.
    • getDoubleValue

      public double getDoubleValue(FormData fd)
      Convenience method that returns the value of this field as a Double.
      Throws:
      NumberFormatException - if the value could not be returned as a double.
    • getBooleanValue

      public boolean getBooleanValue(FormData fd)
      Convenience method that returns the value of this field as a boolean. The value is converted into a boolean as per the invalid input: '{@link Boolean.valueOf(String)'} method.
    • isFilled

      public boolean isFilled(FormData fd)
      Description copied from class: Field
      Returns true if this field was isFilled out or selected by the user, false otherwise.

      Note: Some fields like selects will never be empty since non-multiple select fields always send their default selected value. [although select/with/multiple can be empty since the browser sends (much like radio buttoms) nothing at all when no option is selected].

      Specified by:
      isFilled in class Field
    • reset

      public void reset(FormData fd)
    • trimValues

      public void trimValues(boolean val)
      Trims leading and ending spaces from all entered values. This is true by default. Specify false to turn this off.
    • toString

      public String toString()
      Overrides:
      toString in class Field