org.springframework.web.servlet.tags.form
Class OptionTag

java.lang.Object
  extended by TagSupport
      extended by org.springframework.web.servlet.tags.RequestContextAwareTag
          extended by org.springframework.web.servlet.tags.HtmlEscapingAwareTag
              extended by org.springframework.web.servlet.tags.form.AbstractFormTag
                  extended by org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
                      extended by org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
                          extended by org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag
                              extended by org.springframework.web.servlet.tags.form.OptionTag
All Implemented Interfaces:
EditorAwareTag

public class OptionTag
extends AbstractHtmlElementBodyTag

JSP tag for rendering an HTML 'option' tag.

Must be used nested inside a SelectTag.

Provides full support for databinding by marking an 'option' as 'selected' if the value matches the value bound to the out SelectTag.

The value property is required and corresponds to the 'value' attribute of the rendered 'option'.

An optional label property can be specified, the value of which corresponds to inner text of the rendered 'option' tag. If no label is specified then the value property will be used when rendering the inner text.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller

Field Summary
private  java.lang.String disabled
           
private static java.lang.String DISABLED_ATTRIBUTE
          The name of the 'disabled' attribute.
static java.lang.String DISPLAY_VALUE_VARIABLE_NAME
          The name of the JSP variable used to expose the display value for this tag.
private  java.lang.String label
          The text body of the rendered HTML <option> tag.
private  java.lang.Object oldDisplayValue
           
private  java.lang.Object oldValue
           
private static java.lang.String SELECTED_ATTRIBUTE
          The name of the 'selected' attribute.
private  java.lang.Object value
          The 'value' attribute of the rendered HTML <option> tag.
private static java.lang.String VALUE_ATTRIBUTE
          The name of the 'value' attribute.
static java.lang.String VALUE_VARIABLE_NAME
          The name of the JSP variable used to expose the value for this tag.
 
Fields inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
CLASS_ATTRIBUTE, DIR_ATTRIBUTE, LANG_ATTRIBUTE, ONCLICK_ATTRIBUTE, ONDBLCLICK_ATTRIBUTE, ONKEYDOWN_ATTRIBUTE, ONKEYPRESS_ATTRIBUTE, ONKEYUP_ATTRIBUTE, ONMOUSEDOWN_ATTRIBUTE, ONMOUSEMOVE_ATTRIBUTE, ONMOUSEOUT_ATTRIBUTE, ONMOUSEOVER_ATTRIBUTE, ONMOUSEUP_ATTRIBUTE, STYLE_ATTRIBUTE, TABINDEX_ATTRIBUTE, TITLE_ATTRIBUTE
 
Fields inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
COMMAND_NAME_VARIABLE_NAME, NESTED_PATH_VARIABLE_NAME
 
Fields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE
 
Constructor Summary
OptionTag()
           
 
Method Summary
private  void assertUnderSelectTag()
           
protected  java.lang.String autogenerateId()
          Autogenerate the 'id' attribute value for this tag.
protected  void exposeAttributes()
          Called during AbstractHtmlElementBodyTag.writeTagContent(org.springframework.web.servlet.tags.form.TagWriter) allowing subclasses to add any attributes to the javax.servlet.jsp.PageContext as needed.
protected  BindStatus getBindStatus()
          Get the BindStatus for this tag.
protected  java.lang.String getDisabled()
          Get the value of the 'disabled' attribute.
protected  java.lang.String getLabel()
          Get the text body of the rendered HTML <option> tag.
private  java.lang.String getLabelValue(java.lang.Object resolvedValue)
          Returns the value of the label for this 'option' element.
private  SelectTag getSelectTag()
           
protected  java.lang.Object getValue()
          Get the 'value' attribute of the rendered HTML <option> tag.
protected  boolean isDisabled()
          Is the current HTML tag disabled?
private  boolean isSelected(java.lang.Object resolvedValue)
           
protected  void onWriteTagContent()
          Make sure we are under a 'select' tag before proceeding.
protected  void removeAttributes()
          Called by AbstractHtmlElementBodyTag.doFinally() allowing subclasses to remove any attributes from the javax.servlet.jsp.PageContext as needed.
protected  void renderDefaultContent(TagWriter tagWriter)
           
protected  void renderFromBodyContent(BodyContent bodyContent, TagWriter tagWriter)
          Render the tag contents based on the supplied BodyContent.
private  void renderOption(java.lang.Object value, java.lang.String label, TagWriter tagWriter)
           
private  java.lang.Object resolveValue()
           
 void setDisabled(java.lang.String disabled)
          Set the value of the 'disabled' attribute.
 void setLabel(java.lang.String label)
          Set the text body of the rendered HTML <option> tag.
 void setValue(java.lang.Object value)
          Set the 'value' attribute of the rendered HTML <option> tag.
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag
doEndTag, doFinally, doInitBody, flushBufferedBodyContent, setBodyContent, shouldRender, writeTagContent
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag
getCssClass, getCssErrorClass, getCssStyle, getDir, getDynamicAttributes, getLang, getOnclick, getOndblclick, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getTabindex, getTitle, isValidDynamicAttribute, resolveCssClass, setCssClass, setCssErrorClass, setCssStyle, setDir, setDynamicAttribute, setLang, setOnclick, setOndblclick, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setTabindex, setTitle, writeDefaultAttributes, writeOptionalAttributes
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
convertToDisplayString, getBoundValue, getEditor, getId, getName, getNestedPath, getPath, getPropertyEditor, getPropertyPath, processFieldValue, resolveId, setId, setPath
 
Methods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, evaluateBoolean, getDisplayString, getDisplayString, isDefaultHtmlEscape, writeOptionalAttribute
 
Methods inherited from class org.springframework.web.servlet.tags.HtmlEscapingAwareTag
isHtmlEscape, setHtmlEscape
 
Methods inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doStartTag, getRequestContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_VARIABLE_NAME

public static final java.lang.String VALUE_VARIABLE_NAME
The name of the JSP variable used to expose the value for this tag.

See Also:
Constant Field Values

DISPLAY_VALUE_VARIABLE_NAME

public static final java.lang.String DISPLAY_VALUE_VARIABLE_NAME
The name of the JSP variable used to expose the display value for this tag.

See Also:
Constant Field Values

SELECTED_ATTRIBUTE

private static final java.lang.String SELECTED_ATTRIBUTE
The name of the 'selected' attribute.

See Also:
Constant Field Values

VALUE_ATTRIBUTE

private static final java.lang.String VALUE_ATTRIBUTE
The name of the 'value' attribute.

See Also:
Constant Field Values

DISABLED_ATTRIBUTE

private static final java.lang.String DISABLED_ATTRIBUTE
The name of the 'disabled' attribute.

See Also:
Constant Field Values

value

private java.lang.Object value
The 'value' attribute of the rendered HTML <option> tag.


label

private java.lang.String label
The text body of the rendered HTML <option> tag.


oldValue

private java.lang.Object oldValue

oldDisplayValue

private java.lang.Object oldDisplayValue

disabled

private java.lang.String disabled
Constructor Detail

OptionTag

public OptionTag()
Method Detail

setValue

public void setValue(java.lang.Object value)
Set the 'value' attribute of the rendered HTML <option> tag.

May be a runtime expression.


getValue

protected java.lang.Object getValue()
Get the 'value' attribute of the rendered HTML <option> tag.


setDisabled

public void setDisabled(java.lang.String disabled)
Set the value of the 'disabled' attribute.

May be a runtime expression.

Parameters:
disabled - the value of the 'disabled' attribute

getDisabled

protected java.lang.String getDisabled()
Get the value of the 'disabled' attribute.


isDisabled

protected boolean isDisabled()
                      throws JspException
Is the current HTML tag disabled?

Returns:
true if this tag is disabled
Throws:
JspException

setLabel

public void setLabel(java.lang.String label)
Set the text body of the rendered HTML <option> tag.

May be a runtime expression.


getLabel

protected java.lang.String getLabel()
Get the text body of the rendered HTML <option> tag.


renderDefaultContent

protected void renderDefaultContent(TagWriter tagWriter)
                             throws JspException
Specified by:
renderDefaultContent in class AbstractHtmlElementBodyTag
Throws:
JspException

renderFromBodyContent

protected void renderFromBodyContent(BodyContent bodyContent,
                                     TagWriter tagWriter)
                              throws JspException
Description copied from class: AbstractHtmlElementBodyTag
Render the tag contents based on the supplied BodyContent.

The default implementation simply flushes the BodyContent directly to the output. Subclasses may choose to override this to add additional content to the output.

Overrides:
renderFromBodyContent in class AbstractHtmlElementBodyTag
Throws:
JspException

onWriteTagContent

protected void onWriteTagContent()
Make sure we are under a 'select' tag before proceeding.

Overrides:
onWriteTagContent in class AbstractHtmlElementBodyTag

exposeAttributes

protected void exposeAttributes()
                         throws JspException
Description copied from class: AbstractHtmlElementBodyTag
Called during AbstractHtmlElementBodyTag.writeTagContent(org.springframework.web.servlet.tags.form.TagWriter) allowing subclasses to add any attributes to the javax.servlet.jsp.PageContext as needed.

Overrides:
exposeAttributes in class AbstractHtmlElementBodyTag
Throws:
JspException

getBindStatus

protected BindStatus getBindStatus()
Description copied from class: AbstractDataBoundFormElementTag
Get the BindStatus for this tag.

Overrides:
getBindStatus in class AbstractDataBoundFormElementTag

removeAttributes

protected void removeAttributes()
Description copied from class: AbstractHtmlElementBodyTag
Called by AbstractHtmlElementBodyTag.doFinally() allowing subclasses to remove any attributes from the javax.servlet.jsp.PageContext as needed.

Overrides:
removeAttributes in class AbstractHtmlElementBodyTag

renderOption

private void renderOption(java.lang.Object value,
                          java.lang.String label,
                          TagWriter tagWriter)
                   throws JspException
Throws:
JspException

autogenerateId

protected java.lang.String autogenerateId()
                                   throws JspException
Description copied from class: AbstractDataBoundFormElementTag
Autogenerate the 'id' attribute value for this tag.

The default implementation simply delegates to AbstractDataBoundFormElementTag.getName(), deleting invalid characters (such as "[" or "]").

Overrides:
autogenerateId in class AbstractDataBoundFormElementTag
Throws:
JspException

getLabelValue

private java.lang.String getLabelValue(java.lang.Object resolvedValue)
                                throws JspException
Returns the value of the label for this 'option' element. If the label property is set then the resolved value of that property is used, otherwise the value of the resolvedValue argument is used.

Throws:
JspException

assertUnderSelectTag

private void assertUnderSelectTag()

getSelectTag

private SelectTag getSelectTag()

isSelected

private boolean isSelected(java.lang.Object resolvedValue)

resolveValue

private java.lang.Object resolveValue()
                               throws JspException
Throws:
JspException