net.sourceforge.stripes.tag
Class InputLabelTag

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.InputLabelTag
All Implemented Interfaces:
BodyTag, DynamicAttributes, IterationTag, JspTag, Tag, TryCatchFinally

public class InputLabelTag
extends InputTagSupport
implements BodyTag

Tag handler for a tag that produces an HTML label tag which is capable of looking up localized field names and formatting the label when validation errors exist. The field being labeled is identified using either the name attribute (preferred) or the for attribute. If the name attribute is supplied this will always be used as the lookup key (optionally pre-pended with the form's action path). If the name field is not supplied, the tag will fall back to using the value supplied for the for attribute. This is done because the for attribute is used by HTML as a reference to the id of the input being labeled. In the case where the id is equal to the field name it is unnecessary to specify a name attribute for the label tag. In cases where the field name (or other localized resource name) does not match an HTML ID, the name attribute must be used.

The value used for the label is the localized field name if one exists. Localized field names are looked up in the field name resource bundle first using formActionPath.fieldName, and then (if no value is found) using just fieldName. If no localized String can be found then the body of the label tag is used. If no body is supplied then a warning String will be used instead!

Since:
Stripes 1.1
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
InputLabelTag()
           
 
Method Summary
 int doAfterBody()
          Does nothing.
 int doEndInputTag()
          Performs the main work of the tag as described in the class level javadoc.
 void doInitBody()
          Does nothing.
 int doStartInputTag()
          Does nothing.
 String getFor()
          Gets the HTML ID of the field for which this is a label.
protected  void loadErrors()
          Wraps the parent loadErrors() to suppress exceptions when the label is outside of a stripes form tag.
protected  void registerWithParentForm()
          Overridden to do nothing, since a label isn't really a form field.
 void setFor(String forId)
          Sets the HTML ID of the field for which this is a label.
 void setName(String name)
          Sets the name of the form element/label to be rendered.
 
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, getValueOnPage, hasErrors, isItemSelected, makeFocused, setDisabled, setFocus, setFormatPattern, setFormatType, 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

InputLabelTag

public InputLabelTag()
Method Detail

setFor

public void setFor(String forId)
Sets the HTML ID of the field for which this is a label.


getFor

public String getFor()
Gets the HTML ID of the field for which this is a label.


setName

public void setName(String name)
Sets the name of the form element/label to be rendered. Should only be invoked by the JSP container as it also tracks whether or not the container has set the name, in order to correctly handle pooling.

Overrides:
setName in class InputTagSupport

doStartInputTag

public int doStartInputTag()
                    throws JspException
Does nothing.

Specified by:
doStartInputTag in class InputTagSupport
Returns:
EVAL_BODY_BUFFERED in all cases.
Throws:
JspException

doInitBody

public void doInitBody()
                throws JspException
Does nothing.

Specified by:
doInitBody in interface BodyTag
Throws:
JspException

doAfterBody

public int doAfterBody()
                throws JspException
Does nothing.

Specified by:
doAfterBody in interface IterationTag
Returns:
SKIP_BODY in all cases.
Throws:
JspException

doEndInputTag

public int doEndInputTag()
                  throws JspException
Performs the main work of the tag as described in the class level javadoc.

Specified by:
doEndInputTag in class InputTagSupport
Returns:
EVAL_PAGE in all cases.
Throws:
JspException - if an IOException is encountered writing to the output stream.

registerWithParentForm

protected void registerWithParentForm()
                               throws StripesJspException
Overridden to do nothing, since a label isn't really a form field.

Overrides:
registerWithParentForm in class InputTagSupport
Throws:
StripesJspException - if the parent form tag is not found

loadErrors

protected void loadErrors()
Wraps the parent loadErrors() to suppress exceptions when the label is outside of a stripes form tag.

Overrides:
loadErrors in class InputTagSupport


? Copyright 2005-2006, Stripes Development Team.