Class ChoiceGroup.Choice

java.lang.Object
fc.web.forms.ChoiceGroup.Choice
Enclosing class:
ChoiceGroup

public static class ChoiceGroup.Choice extends Object
Creates a new choice for this choice group. Also note that unlike other fields, the HTML label/text for this choice has to be provided via the constructor (as opposed to being written at the jsp level). See
invalid reference
#htmlBeforeField
.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Choice(String label, boolean selected)
    Constructs a new unselected choice with the specified label (and no separate value attribute)
    Choice(String label, String value)
    Constructs a new unselected choice with the specified value and HTML text.
    Choice(String label, String value, boolean selected)
    Creates a new choice object.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Convenience method that returns the value of this choice as a boolean.
    int
    Convenience method that returns the value of this choice as a Integer.
    Returns the label for this choice.
    short
    Convenience method that returns the value of this choice as a Short.
    Returns the value of this choice.
    boolean
     
    void
    By default, the HTML label (if any) is written after the input element tag but calling this method reverses this order.
    void
    render(FormData fd, Writer writer, boolean disabled)
    Renders this choice maintaining it's selected state by using the specified form data.
    void
    render(Writer writer, boolean selected, boolean disabled)
    Renders this choice with the select state specified by the selected parameter.
    void
    Sets the seperator between labels and the choice.
     
    void
    writeLabel(boolean val)
    Specify true to write the label for this choice, false to skip the label.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Choice

      public Choice(String label, String value, boolean selected)
      Creates a new choice object.
      Parameters:
      label - the label (any html text) for this choice.
      value - the value of this choice item
      selected - true is this choice is originally selected
    • Choice

      public Choice(String label, String value)
      Constructs a new unselected choice with the specified value and HTML text.
      Parameters:
      label - the label (any html text) for this choice
      value - the value of this choice item
    • Choice

      public Choice(String label, boolean selected)
      Constructs a new unselected choice with the specified label (and no separate value attribute)
      Parameters:
      label - the label (any html) text for this choice
      selected - true is this choice is originally selected
  • Method Details

    • labelBeforeField

      public void labelBeforeField()
      By default, the HTML label (if any) is written after the input element tag but calling this method reverses this order.
    • writeLabel

      public void writeLabel(boolean val)
      Specify true to write the label for this choice, false to skip the label. By default, this is true. (false is useful when just the radio button need to be shown, say in a table row with the label shown in a seperate header row).
    • render

      public void render(FormData fd, Writer writer, boolean disabled) throws IOException
      Renders this choice maintaining it's selected state by using the specified form data.

      Each choice can be rendered separately which helps in arbitrary html layout. Choices can also be rendered together via the parent

      invalid @link
      {@link ChoiceGroup#render(FormData, Writer
      } method.
      Throws:
      IOException
    • render

      public void render(Writer writer, boolean selected, boolean disabled) throws IOException
      Renders this choice with the select state specified by the selected parameter.

      Each choice can be rendered separately which helps in arbitrary html layout. Choices can also be rendered together via the parent

      invalid @link
      {@link ChoiceGroup#render(FormData, Writer
      } method.
      Throws:
      IOException
    • getValue

      public String getValue()
      Returns the value of this choice. If no value is set, returns the html text value for this choice tag.
    • getIntValue

      public int getIntValue()
      Convenience method that returns the value of this choice 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 choice as a Short.
      Throws:
      NumberFormatException - if the value could not be returned as a short.
    • getBooleanValue

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

      public String getLabel()
      Returns the label for this choice.
    • setLabelSeperator

      public void setLabelSeperator(String sep)
      Sets the seperator between labels and the choice. Defaults to a space if not set.
    • isOrigSelected

      public boolean isOrigSelected()
      Returns:
      true if this field was originally set to selected, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object