Class OptionTag
- All Implemented Interfaces:
BodyTag,DynamicAttributes,IterationTag,JspTag,Tag,TryCatchFinally,Serializable,EditorAwareTag
<option> tag renders a single HTML 'option'. Sets 'selected' as
appropriate based on bound value.
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.
| Attribute | Required? | Runtime Expression? | Description |
|---|---|---|---|
cssClass |
false |
true |
HTML Optional Attribute |
cssErrorClass |
false |
true |
HTML Optional Attribute. Used when the bound field has errors. |
cssStyle |
false |
true |
HTML Optional Attribute |
dir |
false |
true |
HTML Standard Attribute |
disabled |
false |
true |
HTML Optional Attribute. Setting the value of this attribute to 'true' will disable the HTML element. |
htmlEscape |
false |
true |
Enable/disable HTML escaping of rendered values. |
id |
false |
true |
HTML Standard Attribute |
label |
false |
true |
HTML Optional Attribute |
lang |
false |
true |
HTML Standard Attribute |
onclick |
false |
true |
HTML Event Attribute |
ondblclick |
false |
true |
HTML Event Attribute |
onkeydown |
false |
true |
HTML Event Attribute |
onkeypress |
false |
true |
HTML Event Attribute |
onkeyup |
false |
true |
HTML Event Attribute |
onmousedown |
false |
true |
HTML Event Attribute |
onmousemove |
false |
true |
HTML Event Attribute |
onmouseout |
false |
true |
HTML Event Attribute |
onmouseover |
false |
true |
HTML Event Attribute |
onmouseup |
false |
true |
HTML Event Attribute |
tabindex |
false |
true |
HTML Standard Attribute |
title |
false |
true |
HTML Standard Attribute |
value |
true |
true |
HTML Optional Attribute |
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the JSP variable used to expose the display value for this tag.static final StringThe 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_ATTRIBUTEFields inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
NESTED_PATH_VARIABLE_NAMEFields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTEFields inherited from class jakarta.servlet.jsp.tagext.TagSupport
pageContextFields inherited from interface jakarta.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAGFields inherited from interface jakarta.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAINFields inherited from interface jakarta.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringAutogenerate the 'id' attribute value for this tag.protected voidCalled duringAbstractHtmlElementBodyTag.writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)allowing subclasses to add any attributes to thePageContextas needed.protected BindStatusGet theBindStatusfor this tag.protected StringgetLabel()Get the text body of the rendered HTML<option>tag.protected ObjectgetValue()Get the 'value' attribute of the rendered HTML<option>tag.protected booleanGet the value of the 'disabled' attribute.protected voidMake sure we are under a 'select' tag before proceeding.protected voidCalled byAbstractHtmlElementBodyTag.doFinally()allowing subclasses to remove any attributes from thePageContextas needed.protected voidrenderDefaultContent(TagWriter tagWriter) protected voidrenderFromBodyContent(BodyContent bodyContent, TagWriter tagWriter) Render the tag contents based on the suppliedBodyContent.voidsetDisabled(boolean disabled) Set the value of the 'disabled' attribute.voidSet the text body of the rendered HTML<option>tag.voidSet 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, writeTagContentMethods 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, writeOptionalAttributesMethods inherited from class org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag
convertToDisplayString, getBoundValue, getEditor, getId, getName, getNestedPath, getPath, getPropertyEditor, getPropertyPath, processFieldValue, resolveId, setId, setPathMethods inherited from class org.springframework.web.servlet.tags.form.AbstractFormTag
createTagWriter, doStartTagInternal, evaluate, getDisplayString, getDisplayString, isDefaultHtmlEscape, writeOptionalAttributeMethods inherited from class org.springframework.web.servlet.tags.HtmlEscapingAwareTag
htmlEscape, isHtmlEscape, isResponseEncodedHtmlEscape, setHtmlEscapeMethods inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doStartTag, getRequestContextMethods inherited from class jakarta.servlet.jsp.tagext.TagSupport
doAfterBody, findAncestorWithClass, getParent, getValue, getValues, release, removeValue, setPageContext, setParent, setValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.jsp.tagext.BodyTag
doInitBody, setBodyContentMethods inherited from interface jakarta.servlet.jsp.tagext.IterationTag
doAfterBodyMethods inherited from interface jakarta.servlet.jsp.tagext.Tag
doEndTag, doStartTag, getParent, release, setPageContext, setParent
-
Field Details
-
VALUE_VARIABLE_NAME
The name of the JSP variable used to expose the value for this tag.- See Also:
-
DISPLAY_VALUE_VARIABLE_NAME
The name of the JSP variable used to expose the display value for this tag.- See Also:
-
-
Constructor Details
-
OptionTag
public OptionTag()
-
-
Method Details
-
setValue
Set the 'value' attribute of the rendered HTML<option>tag. -
getValue
Get the 'value' attribute of the rendered HTML<option>tag. -
setDisabled
public void setDisabled(boolean disabled) Set the value of the 'disabled' attribute. -
isDisabled
protected boolean isDisabled()Get the value of the 'disabled' attribute. -
setLabel
Set the text body of the rendered HTML<option>tag.May be a runtime expression.
-
getLabel
Get the text body of the rendered HTML<option>tag. -
renderDefaultContent
- Specified by:
renderDefaultContentin classAbstractHtmlElementBodyTag- Throws:
JspException
-
renderFromBodyContent
protected void renderFromBodyContent(BodyContent bodyContent, TagWriter tagWriter) throws JspException Description copied from class:AbstractHtmlElementBodyTagRender the tag contents based on the suppliedBodyContent.The default implementation simply
flushestheBodyContentdirectly to the output. Subclasses may choose to override this to add additional content to the output.- Overrides:
renderFromBodyContentin classAbstractHtmlElementBodyTag- Throws:
JspException
-
onWriteTagContent
protected void onWriteTagContent()Make sure we are under a 'select' tag before proceeding.- Overrides:
onWriteTagContentin classAbstractHtmlElementBodyTag
-
exposeAttributes
Description copied from class:AbstractHtmlElementBodyTagCalled duringAbstractHtmlElementBodyTag.writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)allowing subclasses to add any attributes to thePageContextas needed.- Overrides:
exposeAttributesin classAbstractHtmlElementBodyTag- Throws:
JspException
-
getBindStatus
Description copied from class:AbstractDataBoundFormElementTagGet theBindStatusfor this tag.- Overrides:
getBindStatusin classAbstractDataBoundFormElementTag
-
removeAttributes
protected void removeAttributes()Description copied from class:AbstractHtmlElementBodyTagCalled byAbstractHtmlElementBodyTag.doFinally()allowing subclasses to remove any attributes from thePageContextas needed.- Overrides:
removeAttributesin classAbstractHtmlElementBodyTag
-
autogenerateId
Description copied from class:AbstractDataBoundFormElementTagAutogenerate the 'id' attribute value for this tag.The default implementation simply delegates to
AbstractDataBoundFormElementTag.getName(), deleting invalid characters (such as "[" or "]").- Overrides:
autogenerateIdin classAbstractDataBoundFormElementTag- Throws:
JspException
-