net.sourceforge.stripes.tag
Class InputOptionsCollectionTag

java.lang.Object
  extended by net.sourceforge.stripes.tag.StripesTagSupport
      extended by net.sourceforge.stripes.tag.HtmlTagSupport
          extended by net.sourceforge.stripes.tag.InputOptionsCollectionTag
All Implemented Interfaces:
JspTag, Tag

public class InputOptionsCollectionTag
extends HtmlTagSupport
implements 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.

All other attributes on the tag (other than collection, value and label) 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.

Author:
Tim Fennell

Field Summary
 
Fields inherited from class net.sourceforge.stripes.tag.StripesTagSupport
pageContext, parentTag
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
InputOptionsCollectionTag()
           
 
Method Summary
 int doEndTag()
          Does nothing.
 int doStartTag()
          Iterates through the collection and uses an instance of InputOptionTag to generate each individual option with the correct state.
 Collection getCollection()
          Returns the value set with setCollection().
 String getLabel()
          Gets the property name set with setLabel().
 String getValue()
          Returns the property name set with setValue().
 void setCollection(Collection collection)
          Sets the collection that will be used to generate options.
 void setLabel(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 setValue(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.
 
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, 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
getPageContext, getParent, getParentTag, 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.Tag
getParent, release, setPageContext, setParent
 

Constructor Detail

InputOptionsCollectionTag

public InputOptionsCollectionTag()
Method Detail

setCollection

public void setCollection(Collection collection)
Sets the collection that will be used to generate options.


getCollection

public Collection getCollection()
Returns the value set with setCollection().


setValue

public void setValue(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.

Parameters:
value - the name of the attribute

getValue

public String getValue()
Returns the property name set with setValue().


setLabel

public void setLabel(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. what is seen by the user).

Parameters:
label - the name of the attribute

getLabel

public String getLabel()
Gets the property name set with setLabel().


doStartTag

public int doStartTag()
               throws JspException
Iterates through the collection and uses an instance of InputOptionTag to generate each individual option with the correct state. It is assumed that each element in the collection has non-null values for the properties specified for generating the label and value.

Specified by:
doStartTag in interface Tag
Specified by:
doStartTag in class StripesTagSupport
Returns:
SKIP_BODY in all cases
Throws:
JspException - if either the label or value attributes specify properties that are not present on the beans in the collection, or output cannot be written.

doEndTag

public int doEndTag()
             throws JspException
Does nothing.

Specified by:
doEndTag in interface Tag
Specified by:
doEndTag in class StripesTagSupport
Returns:
EVAL_PAGE in all cases.
Throws:
JspException


© Copyright 2005, Stripes Development Team.