net.sourceforge.stripes.tag
Class InputCheckBoxTag

java.lang.Object
  extended by net.sourceforge.stripes.tag.StripesTagSupport
      extended by net.sourceforge.stripes.tag.HtmlTagSupport
          extended by net.sourceforge.stripes.tag.InputTagSupport
              extended by net.sourceforge.stripes.tag.InputCheckBoxTag
All Implemented Interfaces:
BodyTag, DynamicAttributes, IterationTag, JspTag, Tag, TryCatchFinally

public class InputCheckBoxTag
extends InputTagSupport
implements BodyTag

Implements an HTML tag that generates form fields of type <input type="checkbox"/>. Since a single checkbox widget on a HTML page can have only a single value, the value tag attribute must always resolve to a scalar value which will be converted to a String using the Stripes Formatting system, or by caling toString() if an appropriate Formatter is not found.

Checkboxes perform automatic (re-)population of state. They prefer, in order, values in the HttpServletRequest, values in the ActionBean and lastly values set using checked="" on the page. The "checked" attribute is a complex attribute and may be a Collection, an Array or a scalar Java Object. In the first two cases a check is performed to see if the value in the value="foo" attribute is one of the elements in the checked collection or array. In the last case, the value is matched directly against the String form of the checked attribute. If in any case a checkbox's value matches then a checked="checked" attribute will be added to the HTML written.

The tag may include a body and if present the body is converted to a String and overrides the checked tag attribute.

Author:
Tim Fennell

Field Summary
 
Fields inherited from class net.sourceforge.stripes.tag.InputTagSupport
errorRenderer, fieldErrors
 
Fields inherited from class net.sourceforge.stripes.tag.StripesTagSupport
pageContext, parentTag
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
InputCheckBoxTag()
          Basic constructor that sets the input tag's type attribute to "checkbox".
 
Method Summary
 int doAfterBody()
          Ensure that the body is evaluated only once.
 int doEndInputTag()
          Does the main work of the tag, including determining the tags state (checked or not) and writing out a singleton tag representing the checkbox.
 void doInitBody()
          Does nothing.
 int doStartInputTag()
          Does nothing.
 Object getChecked()
          Returns the value originally set using setChecked().
 Object getValue()
          Returns the value that this checkbox will submit if it is checked.
 Object getValueOnPage()
          Returns the body of the tag if it is present and not empty, otherwise returns the value of the 'checked' attribute.
 void setChecked(Object checked)
          Sets the default checked values for checkboxes with this name.
 void setValue(Object value)
          Sets the value that this checkbox will submit if it is checked.
 
Methods inherited from class net.sourceforge.stripes.tag.InputTagSupport
doCatch, doEndTag, doFinally, doStartTag, format, format, getActionBean, getDisabled, getFieldErrors, getFormatPattern, getFormatType, getLocalizedFieldName, getLocalizedFieldName, getName, getOverrideValueOrValues, getParentFormTag, getReadonly, getSingleOverrideValue, getSize, getValidationMetadata, hasErrors, isItemSelected, loadErrors, makeFocused, registerWithParentForm, setDisabled, setFocus, setFormatPattern, setFormatType, setName, setReadonly, setSize
 
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, 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
 
Methods inherited from class net.sourceforge.stripes.tag.StripesTagSupport
getActionBeanType, getActionBeanUrl, getPageContext, getParent, getParentTag, getTagStack, popPageContextAttributes, pushPageContextAttributes, 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.BodyTag
setBodyContent
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
doEndTag, doStartTag, getParent, release, setPageContext, setParent
 

Constructor Detail

InputCheckBoxTag

public InputCheckBoxTag()
Basic constructor that sets the input tag's type attribute to "checkbox".

Method Detail

setChecked

public void setChecked(Object checked)
Sets the default checked values for checkboxes with this name.

Parameters:
checked - may be either a Collection or Array of checked values, or a single Checked value. Values do not have to be Strings, but will need to be convertible to String using the toString() method.

getChecked

public Object getChecked()
Returns the value originally set using setChecked().


setValue

public void setValue(Object value)
Sets the value that this checkbox will submit if it is checked.


getValue

public Object getValue()
Returns the value that this checkbox will submit if it is checked.


doStartInputTag

public int doStartInputTag()
                    throws JspException
Does nothing.

Specified by:
doStartInputTag in class InputTagSupport
Throws:
JspException

doInitBody

public void doInitBody()
                throws JspException
Does nothing.

Specified by:
doInitBody in interface BodyTag
Throws:
JspException

doAfterBody

public int doAfterBody()
                throws JspException
Ensure that the body is evaluated only once.

Specified by:
doAfterBody in interface IterationTag
Throws:
JspException

getValueOnPage

public Object getValueOnPage()
Returns the body of the tag if it is present and not empty, otherwise returns the value of the 'checked' attribute.

Overrides:
getValueOnPage in class InputTagSupport
Returns:
May return any of String[], Collection or Object

doEndInputTag

public int doEndInputTag()
                  throws JspException
Does the main work of the tag, including determining the tags state (checked or not) and writing out a singleton tag representing the checkbox.

Specified by:
doEndInputTag in class InputTagSupport
Returns:
always returns EVAL_PAGE to continue page execution
Throws:
JspException - if the checkbox is not contained inside a stripes InputFormTag, or has problems writing to the output.


? Copyright 2005-2006, Stripes Development Team.