net.sourceforge.stripes.tag
Class InputOptionsEnumerationTag

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

public class InputOptionsEnumerationTag
extends HtmlTagSupport
implements Tag

Writes a set of <option value="foo">bar</option> tags to the page based on the values of a enum. Each value in the enum is represented by a single option tag on the page. The options will be generated in ordinal value order (i.e. the order they are declared in the enum). Uses the label attribute on the tag to name the property of the enum that should be used to generate the body of the HTML option tag. If the label attribute is not set then the tag will call toString() on the enum value and use that as the body of the tag.

E.g. a tag declaration that looks like:

<stripes:options-enumeration collection="net.kitty.EyeColor"/>

would result in the tag attempting to invoke Class.forName("net.kitty.EyeColor") and cast the result to type Class. If that fails, a JspException will be raised. The tag will then proceed to call name() in order to fetch the value of the enum and use that for the value of the option, and call toString() to provide the body of the option because a label attribute was not specified.

All other attributes on the tag (other than enum 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
InputOptionsEnumerationTag()
           
 
Method Summary
 int doEndTag()
          Does nothing.
 int doStartTag()
          Attempts to instantiate the Class object representing the enum and fetch the values of the enum.
 String getEnum()
          Gets the enum class name set with setEnum().
 String getLabel()
          Gets the name of the property that will be used to generate the option's label.
 void setEnum(String name)
          Sets the fully qualified name of an enumeration class.
 void setLabel(String label)
          Sets the name of the property that will be used to generate the option's label.
 
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

InputOptionsEnumerationTag

public InputOptionsEnumerationTag()
Method Detail

setEnum

public void setEnum(String name)
Sets the fully qualified name of an enumeration class.


getEnum

public String getEnum()
Gets the enum class name set with setEnum().


setLabel

public void setLabel(String label)
Sets the name of the property that will be used to generate the option's label.


getLabel

public String getLabel()
Gets the name of the property that will be used to generate the option's label.


doStartTag

public int doStartTag()
               throws JspException
Attempts to instantiate the Class object representing the enum and fetch the values of the enum. Then generates an option per value using an instance of an InputOptionTag.

Specified by:
doStartTag in interface Tag
Specified by:
doStartTag in class StripesTagSupport
Returns:
SKIP_BODY in all cases.
Throws:
JspException - if the class name supplied is not a valid class, or cannot be cast to Class.

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.