fc.web.forms
Class ChoiceGroup.Choice

java.lang.Object
  extended by 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 #htmlBeforeField.


Constructor Summary
ChoiceGroup.Choice(String label, boolean selected)
          Constructs a new unselected choice with the specified label (and no separate value attribute)
ChoiceGroup.Choice(String label, String value)
          Constructs a new unselected choice with the specified value and HTML text.
ChoiceGroup.Choice(String label, String value, boolean selected)
          Creates a new choice object.
 
Method Summary
 boolean getBooleanValue(FormData fd)
          Convenience method that returns the value of this choice as a boolean.
 int getIntValue()
          Convenience method that returns the value of this choice as a Integer.
 String getLabel()
          Returns the label for this choice.
 short getShortValue(FormData fd)
          Convenience method that returns the value of this choice as a Short.
 String getValue()
          Returns the value of this choice.
 boolean isOrigSelected()
           
 void labelBeforeField()
          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 setLabelSeperator(String sep)
          Sets the seperator between labels and the choice.
 String toString()
           
 void writeLabel(boolean val)
          Specify true to write the label for this choice, false to skip the label.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChoiceGroup.Choice

public ChoiceGroup.Choice(String label,
                          String value,
                          boolean selected)
Creates a new choice object.

Parameters:
value - the value of this choice item
label - the label (any html text) for this choice.
selected - true is this choice is originally selected

ChoiceGroup.Choice

public ChoiceGroup.Choice(String label,
                          String value)
Constructs a new unselected choice with the specified value and HTML text.

Parameters:
value - the value of this choice item
label - the label (any html text) for this choice

ChoiceGroup.Choice

public ChoiceGroup.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 Detail

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 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 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 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