net.sourceforge.stripes.tag
Class InputOptionTag

java.lang.Object
  extended by net.sourceforge.stripes.tag.StripesTagSupport
      extended by net.sourceforge.stripes.tag.HtmlTagSupport
          extended by net.sourceforge.stripes.tag.InputTagSupport
              extended by net.sourceforge.stripes.tag.InputOptionTag
All Implemented Interfaces:
BodyTag, DynamicAttributes, IterationTag, JspTag, Tag, TryCatchFinally

public class InputOptionTag
extends InputTagSupport
implements BodyTag

Generates an <option value="foo">Fooey</option> HTML tag. Coordinates with an enclosing select tag to determine it's state (i.e. whether or not it is selected.) As a result some of the logic regarding state repopulation is a bit complex.

Since options can have only a single value per option the value attribute of the tag must be a scalar, which will be converted into a String using a Formatter if an appropriate one can be found, otherwise the toString() method will be invoked. The presence of a "selected" attribute is used as an indication that this option believes it should be selected by default - the value (as opposed to the presence) of the selected attribute is never used....

The option tag delegates to its enclosing select tag to determine whether or not it should be selected. See the "select tag" for documentation on how it determines selection status. If the select tag has no opinion on selection state (note that this is not the same as select tag deeming the option should not be selected) then the presence of the selected attribute (or lack thereof) is used to turn selection on or off.

If the option has a body then the String value of that body will be used to generate the body of the generated HTML option. If the body is empty or not present then the label attribute will be written into the body of the tag.

Author:
Tim Fennell

Field Summary
 
Fields inherited from class net.sourceforge.stripes.tag.InputTagSupport
errorRenderer, fieldErrors
 
Fields inherited from class net.sourceforge.stripes.tag.StripesTagSupport
pageContext, parentTag
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
InputOptionTag()
           
 
Method Summary
 int doAfterBody()
          Does nothing.
 int doEndInputTag()
          Locates the option's parent select tag, determines selection state and then writes out an option tag with an appropriate body.
 void doInitBody()
          Does nothing.
 int doStartInputTag()
          Does nothing.
 String getLabel()
          Returns the value set with setLabel().
 String getSelected()
          Returns the value set with setSelected().
 Object getValue()
          Returns the value of the option as set with setValue().
protected  void registerWithParentForm()
          Overridden to make sure that options do not try and register themselves with the form tag.
 void setLabel(String label)
          Sets the label that will be used as the option body if no body is supplied.
 void setSelected(String selected)
          Sets whether or not this option believes it should be selected by default.
 void setValue(Object value)
          Sets the value of this option.
 
Methods inherited from class net.sourceforge.stripes.tag.InputTagSupport
doCatch, doEndTag, doFinally, doStartTag, format, format, getActionBean, getDisabled, getFieldErrors, getFormatPattern, getFormatType, getLocalizedFieldName, getLocalizedFieldName, getName, getOverrideValueOrValues, getParentFormTag, getReadonly, getSingleOverrideValue, getSize, getValidationMetadata, getValueOnPage, hasErrors, isItemSelected, loadErrors, makeFocused, setDisabled, setFocus, setFormatPattern, setFormatType, setName, setReadonly, setSize
 
Methods inherited from class net.sourceforge.stripes.tag.HtmlTagSupport
evaluateExpression, get, getAccesskey, getAttributes, getBodyContent, getBodyContentAsString, getCssClass, getDir, getId, getLang, getOnblur, getOnchange, getOnclick, getOndblclick, getOnfocus, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getOnselect, getStyle, getTabindex, getTitle, release, set, setAccesskey, setBodyContent, setClass, setCssClass, setDir, setDynamicAttribute, setId, setLang, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setStyle, setTabindex, setTitle, toString, writeAttributes, writeCloseTag, writeOpenTag, writeSingletonTag
 
Methods inherited from class net.sourceforge.stripes.tag.StripesTagSupport
getActionBeanType, getActionBeanUrl, getPageContext, getParent, getParentTag, getTagStack, popPageContextAttributes, pushPageContextAttributes, setPageContext, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.BodyTag
setBodyContent
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
doEndTag, doStartTag, getParent, release, setPageContext, setParent
 

Constructor Detail

InputOptionTag

public InputOptionTag()
Method Detail

setValue

public void setValue(Object value)
Sets the value of this option.


getValue

public Object getValue()
Returns the value of the option as set with setValue().


setLabel

public void setLabel(String label)
Sets the label that will be used as the option body if no body is supplied.


getLabel

public String getLabel()
Returns the value set with setLabel().


setSelected

public void setSelected(String selected)
Sets whether or not this option believes it should be selected by default.


getSelected

public String getSelected()
Returns the value set with setSelected().


doStartInputTag

public int doStartInputTag()
                    throws JspException
Does nothing.

Specified by:
doStartInputTag in class InputTagSupport
Returns:
EVAL_BODY_BUFFERED in all cases.
Throws:
JspException

doInitBody

public void doInitBody()
                throws JspException
Does nothing.

Specified by:
doInitBody in interface BodyTag
Throws:
JspException

doAfterBody

public int doAfterBody()
                throws JspException
Does nothing.

Specified by:
doAfterBody in interface IterationTag
Returns:
SKIP_BODY in all cases.
Throws:
JspException

doEndInputTag

public int doEndInputTag()
                  throws JspException
Locates the option's parent select tag, determines selection state and then writes out an option tag with an appropriate body.

Specified by:
doEndInputTag in class InputTagSupport
Returns:
EVAL_PAGE in all cases.
Throws:
JspException - if the option is not contained inside an InputSelectTag or output cannot be written.

registerWithParentForm

protected void registerWithParentForm()
                               throws StripesJspException
Overridden to make sure that options do not try and register themselves with the form tag. This is done because options are not standalone input tags, but always part of a select tag (which gets registered).

Overrides:
registerWithParentForm in class InputTagSupport
Throws:
StripesJspException - if the parent form tag is not found


? Copyright 2005-2006, Stripes Development Team.