public class InputOptionsCollectionTag extends HtmlTagSupport implements javax.servlet.jsp.tagext.Tag
Writes a set of <option value="foo">bar</option> tags to the page based on the contents of a Collection. Each element in the collection is represented by a single option tag on the page. Uses the label and value attributes on the tag to name the properties of the objects in the Collection that should be used to generate the body of the HTML option tag and the value attribute of the HTML option tag respectively.
E.g. a tag declaration that looks like:
<stripes:options-collection collection="${cats} value="catId" label="name"/>
would cause the container to look for a Collection called "cats" across the various JSP scopes and set it on the tag. The tag would then proceed to iterate through that collection calling getCatId() and getName() on each cat to produce HTML option tags.
The tag will attempt to localize the labels attributes of the option tags that are generated. To do this it will look up labels in the field resource bundle using:
For example for a class com.myco.Gender supplied to the options-collection tag with label="description" and value="key", when rendering for an instance Gender[key="M", description="Male"] the following localized properties will be looked for:
If no localized label can be found then the value of the label property will be used.
Optionally, the group attribute may be used to generate <optgroup> tags. The value of this attribute is used to retrieve the corresponding property on each object of the collection. A new optgroup will be created each time the value changes.
The rendered group may be localized by specifying one of the following properties:
All other attributes on the tag (other than collection, value, label and group) are passed directly through to the InputOptionTag which is used to generate the individual HTML options tags. As a result the InputOptionsCollectionTag will exhibit the same re-population/selection behaviour as the regular options tag.
Since the tag has no use for one it does not allow a body.
Modifier and Type | Class and Description |
---|---|
static class |
InputOptionsCollectionTag.Entry
A little container class that holds an entry in the collection of items being used
to generate the options, along with the determined label and value (either from a
property, or a localized value).
|
pageContext, parentTag
Constructor and Description |
---|
InputOptionsCollectionTag() |
Modifier and Type | Method and Description |
---|---|
protected void |
addEntry(java.lang.Object item,
java.lang.Object label,
java.lang.Object value)
Adds an entry to the internal list of items being used to generate options.
|
protected void |
addEntry(java.lang.Object item,
java.lang.Object label,
java.lang.Object value,
java.lang.Object group)
Adds an entry to the internal list of items being used to generate options.
|
int |
doEndTag()
Optionally sorts the assembled entries and then renders them into a series of
option tags using an instance of InputOptionTag to do the rendering work.
|
int |
doStartTag()
Iterates through the collection and generates the list of Entry objects that can then
be sorted and rendered into options.
|
java.lang.Object |
getCollection()
Returns the value set by
setCollection(Object) . |
java.lang.String |
getGroup()
Gets the property name set with setGroup().
|
java.lang.String |
getLabel()
Gets the property name set with setLabel().
|
java.lang.String |
getSort()
Gets the comma separated list of properties by which the collection is sorted.
|
java.lang.String |
getValue()
Returns the property name set with setValue().
|
void |
setCollection(java.lang.Object in)
Sets the collection that will be used to generate options.
|
void |
setGroup(java.lang.String group)
Sets the name of the property that will be fetched on each bean in the collection in
order to generate optgroups.
|
void |
setLabel(java.lang.String label)
Sets the name of the property that will be fetched on each bean in the collection in
order to generate the body of each option (i.e.
|
void |
setSort(java.lang.String sort)
Sets a comma separated list of properties by which the beans in the collection will
be sorted prior to rendering them as options.
|
void |
setValue(java.lang.String value)
Sets the name of the property that will be fetched on each bean in the collection in
order to generate the value attribute of each option.
|
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
getActionBeanType, getActionBeanUrl, getPageContext, getParent, getParentTag, getTagStack, popPageContextAttributes, pushPageContextAttributes, setPageContext, setParent
public void setCollection(java.lang.Object in)
Sets the collection that will be used to generate options. In this case the term
collection is used in the loosest possible sense - it means either a bonafide instance
of Collection
, or an implementation of Iterable
other than a
Collection, or an array of Objects or primitives.
In the case of any input which is not an Collection
it is converted
to a Collection before storing it.
in
- either a Collection, an Iterable or an Arraypublic java.lang.Object getCollection()
setCollection(Object)
. In the case that a
Collection
was supplied, the same collection will be returned. In all
other cases a new collection created to hold the supplied elements will be returned.public void setValue(java.lang.String value)
value
- the name of the attributepublic java.lang.String getValue()
public void setLabel(java.lang.String label)
label
- the name of the attributepublic java.lang.String getLabel()
public void setSort(java.lang.String sort)
sort
- the name of the attribute(s) used to sort the collection of optionspublic java.lang.String getSort()
protected void addEntry(java.lang.Object item, java.lang.Object label, java.lang.Object value)
item
- the object represented by the optionlabel
- the actual label for the optionvalue
- the actual value for the optionprotected void addEntry(java.lang.Object item, java.lang.Object label, java.lang.Object value, java.lang.Object group)
item
- the object represented by the optionlabel
- the actual label for the optionvalue
- the actual value for the optiongroup
- the value to be used for optgroupspublic int doStartTag() throws javax.servlet.jsp.JspException
doStartTag
in interface javax.servlet.jsp.tagext.Tag
doStartTag
in class StripesTagSupport
javax.servlet.jsp.JspException
- if either the label or value attributes specify properties that are
not present on the beans in the collectionpublic int doEndTag() throws javax.servlet.jsp.JspException
doEndTag
in interface javax.servlet.jsp.tagext.Tag
doEndTag
in class StripesTagSupport
javax.servlet.jsp.JspException
public void setGroup(java.lang.String group)
group
- the name of the group attributepublic java.lang.String getGroup()
? Copyright 2005-2006, Stripes Development Team.