net.sourceforge.stripes.tag
Class InputTagSupport

java.lang.Object
  extended by net.sourceforge.stripes.tag.StripesTagSupport
      extended by net.sourceforge.stripes.tag.HtmlTagSupport
          extended by net.sourceforge.stripes.tag.InputTagSupport
All Implemented Interfaces:
DynamicAttributes, JspTag, Tag, TryCatchFinally
Direct Known Subclasses:
InputButtonSupportTag, InputCheckBoxTag, InputFileTag, InputHiddenTag, InputImageTag, InputLabelTag, InputOptionTag, InputRadioButtonTag, InputSelectTag, InputTextAreaTag, InputTextTag

public abstract class InputTagSupport
extends HtmlTagSupport
implements TryCatchFinally

Parent class for all input tags in stripes. Provides support methods for retrieving all the attributes that are shared across form input tags. Also provides accessors for finding the specified "override" value and for finding the enclosing support tag.

Author:
Tim Fennell

Field Summary
protected  TagErrorRenderer errorRenderer
          The error renderer to be utilized for error output of this input tag
protected  List<ValidationError> fieldErrors
          A list of the errors related to this input tag instance
 
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
InputTagSupport()
           
 
Method Summary
 void doCatch(Throwable throwable)
          Rethrows the passed in throwable in all cases.
abstract  int doEndInputTag()
          Abstract method implemented in child classes instead of doEndTag().
 int doEndTag()
          Final implementation of the doEndTag() method that allows the base InputTagSupport class to insert functionality before and after the tag performs it's doEndTag equivalent method.
 void doFinally()
          Used to ensure that the input tag is always removed from the tag stack so that there is never any confusion about tag-parent hierarchies.
abstract  int doStartInputTag()
          Abstract method implemented in child classes instead of doStartTag().
 int doStartTag()
          Final implementation of the doStartTag() method that allows the base InputTagSupport class to insert functionality before and after the tag performs it's doStartTag equivalent method.
protected  String format(Object input)
          Calls format(Object, boolean) with forOutput set to true.
protected  String format(Object input, boolean forOutput)
          Attempts to format an object using the Stripes formatting system.
 ActionBean getActionBean()
          Fetches the ActionBean associated with the form if one is present.
 String getDisabled()
           
 List<ValidationError> getFieldErrors()
          Access for the field errors that occurred on the form input this tag represents
 String getFormatPattern()
          Returns the value set with setFormatPattern()
 String getFormatType()
          Returns the value set with setFormatAs()
 String getLocalizedFieldName()
          Fetches the localized name for this field if one exists in the resource bundle.
protected  String getLocalizedFieldName(String name)
          Attempts to fetch a "field name" resource from the localization bundle.
 String getName()
           
protected  Object getOverrideValueOrValues()
          Gets the value for this tag based on the current population strategy.
 FormTag getParentFormTag()
          Locates the enclosing stripes form tag.
 String getReadonly()
          Gets the HTML attribute of the same name.
protected  Object getSingleOverrideValue()
          Returns a single value for the the value of this field.
 String getSize()
           
protected  ValidationMetadata getValidationMetadata()
           
 Object getValueOnPage()
          Used during repopulation to query the tag for a value of values provided to the tag on the JSP.
 boolean hasErrors()
          Returns true if one or more validation errors exist for the field represented by this input tag.
protected  boolean isItemSelected(Object value, Object selected)
          Utility method for determining if a String value is contained within an Object, where the object may be either a String, String[], Object, Object[] or Collection.
protected  void loadErrors()
          Find errors that are related to the form field this input tag represents and place them in an instance variable to use during error rendering.
protected  void makeFocused()
          Writes out a JavaScript string to set focus on the field as it is rendered.
protected  void registerWithParentForm()
          Registers the field with the parent form within which it must be enclosed.
 void setDisabled(String disabled)
          Checks to see if the value provided is either 'disabled' or a value that the BooleanTypeConverter believes it true.
 void setFocus(boolean focus)
          Informs the tag that it should render JavaScript to ensure that it is focused when the page is loaded.
 void setFormatPattern(String formatPattern)
          Sets the named format pattern, or a custom format pattern.
 void setFormatType(String formatType)
          Sets the type of output to format, e.g.
 void setName(String name)
           
 void setReadonly(String readonly)
          Sets the value of the readonly attribute to "readonly" but only when the value passed in is either "readonly" itself, or is converted to true by the BooleanTypeConverter.
 void setSize(String size)
           
 
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
 

Field Detail

fieldErrors

protected List<ValidationError> fieldErrors
A list of the errors related to this input tag instance


errorRenderer

protected TagErrorRenderer errorRenderer
The error renderer to be utilized for error output of this input tag

Constructor Detail

InputTagSupport

public InputTagSupport()
Method Detail

setFormatType

public void setFormatType(String formatType)
Sets the type of output to format, e.g. date or time.


getFormatType

public String getFormatType()
Returns the value set with setFormatAs()


setFormatPattern

public void setFormatPattern(String formatPattern)
Sets the named format pattern, or a custom format pattern.


getFormatPattern

public String getFormatPattern()
Returns the value set with setFormatPattern()


getOverrideValueOrValues

protected Object getOverrideValueOrValues()
                                   throws StripesJspException
Gets the value for this tag based on the current population strategy. The value returned could be a scalar value, or it could be an array or collection depending on what the population strategy finds. For example, if the user submitted multiple values for a checkbox, the default population strategy would return a String[] containing all submitted values.

Returns:
Object either a value/values for this tag or null
Throws:
StripesJspException - if the enclosing form tag (which is required at all times, and necessary to perform repopulation) cannot be located

getSingleOverrideValue

protected Object getSingleOverrideValue()
                                 throws StripesJspException
Returns a single value for the the value of this field. This can be used to ensure that only a single value is returned by the population strategy, which is useful in the case of text inputs etc. which can have only a single value.

Returns:
Object either a single value or null
Throws:
StripesJspException - if the enclosing form tag (which is required at all times, and necessary to perform repopulation) cannot be located

getValueOnPage

public Object getValueOnPage()
Used during repopulation to query the tag for a value of values provided to the tag on the JSP. This allows the PopulationStrategy to encapsulate all decisions about which source to use when repopulating tags.

Returns:
May return any of String[], Collection or Object

getParentFormTag

public FormTag getParentFormTag()
                         throws StripesJspException

Locates the enclosing stripes form tag. If no form tag can be found, because the tag was not enclosed in one on the JSP, an exception is thrown.

Returns:
FormTag the enclosing form tag on the JSP
Throws:
StripesJspException - if an enclosing form tag cannot be found

isItemSelected

protected boolean isItemSelected(Object value,
                                 Object selected)
Utility method for determining if a String value is contained within an Object, where the object may be either a String, String[], Object, Object[] or Collection. Used primarily by the InputCheckBoxTag and InputSelectTag to determine if specific check boxes or options should be selected based on the values contained in the JSP, HttpServletRequest and the ActionBean.

Parameters:
value - the value that we are searching for
selected - a String, String[], Object, Object[] or Collection (of scalars) denoting the selected items
Returns:
boolean true if the String can be found, false otherwise

getLocalizedFieldName

public String getLocalizedFieldName()
                             throws StripesJspException
Fetches the localized name for this field if one exists in the resource bundle. Relies on there being a "name" attribute on the tag, and the pageContext being set on the tag. First checks for a value of {actionBean FQN}.{fieldName} in the specified bundle, then {actionPath}.{fieldName} then just "fieldName".

Returns:
a localized field name if one can be found, or null if one cannot be found.
Throws:
StripesJspException

getLocalizedFieldName

protected String getLocalizedFieldName(String name)
                                throws StripesJspException
Attempts to fetch a "field name" resource from the localization bundle. Delegates to LocalizationUtility.getLocalizedFieldName(String, String, Class, java.util.Locale)

Parameters:
name - the field name or resource to look up
Returns:
the localized String corresponding to the name provided
Throws:
StripesJspException

getValidationMetadata

protected ValidationMetadata getValidationMetadata()
                                            throws StripesJspException
Throws:
StripesJspException

format

protected String format(Object input)
Calls format(Object, boolean) with forOutput set to true.

Parameters:
input - The object to be formatted
See Also:
format(Object, boolean)

format

protected String format(Object input,
                        boolean forOutput)
Attempts to format an object using the Stripes formatting system. If no formatter can be found, then a simple String.valueOf(input) will be returned. If the value passed in is null, then the empty string will be returned.

Parameters:
input - The object to be formatted
forOutput - If true, then the object will be formatted for output to the JSP. Currently, that means that if encryption is enabled for the ActionBean property with the same name as this tag then the formatted value will be encrypted before it is returned.

loadErrors

protected void loadErrors()
                   throws StripesJspException
Find errors that are related to the form field this input tag represents and place them in an instance variable to use during error rendering.

Throws:
StripesJspException

getFieldErrors

public List<ValidationError> getFieldErrors()
                                     throws StripesJspException
Access for the field errors that occurred on the form input this tag represents

Returns:
List the list of validation errors for this field
Throws:
StripesJspException

hasErrors

public boolean hasErrors()
                  throws StripesJspException
Returns true if one or more validation errors exist for the field represented by this input tag.

Throws:
StripesJspException

getActionBean

public ActionBean getActionBean()
                         throws StripesJspException
Fetches the ActionBean associated with the form if one is present. An ActionBean will not be created (and hence not present) by default. An ActionBean will only be present if the current request got bound to the same ActionBean as the current form uses. E.g. if we are re-showing the page as the result of an error, or the same ActionBean is used for a "pre-Action" and the "post-action".

Returns:
ActionBean the ActionBean bound to the form if there is one
Throws:
StripesJspException

doStartTag

public final int doStartTag()
                     throws JspException
Final implementation of the doStartTag() method that allows the base InputTagSupport class to insert functionality before and after the tag performs it's doStartTag equivalent method. Finds errors related to this field and intercepts with a TagErrorRenderer if appropriate.

Specified by:
doStartTag in interface Tag
Specified by:
doStartTag in class StripesTagSupport
Returns:
int the value returned by the child class from doStartInputTag()
Throws:
JspException

registerWithParentForm

protected void registerWithParentForm()
                               throws StripesJspException
Registers the field with the parent form within which it must be enclosed.

Throws:
StripesJspException - if the parent form tag is not found

doStartInputTag

public abstract int doStartInputTag()
                             throws JspException
Abstract method implemented in child classes instead of doStartTag().

Throws:
JspException

doEndTag

public final int doEndTag()
                   throws JspException
Final implementation of the doEndTag() method that allows the base InputTagSupport class to insert functionality before and after the tag performs it's doEndTag equivalent method.

Specified by:
doEndTag in interface Tag
Specified by:
doEndTag in class StripesTagSupport
Returns:
int the value returned by the child class from doStartInputTag()
Throws:
JspException

doCatch

public void doCatch(Throwable throwable)
             throws Throwable
Rethrows the passed in throwable in all cases.

Specified by:
doCatch in interface TryCatchFinally
Throws:
Throwable

doFinally

public void doFinally()
Used to ensure that the input tag is always removed from the tag stack so that there is never any confusion about tag-parent hierarchies.

Specified by:
doFinally in interface TryCatchFinally

setFocus

public void setFocus(boolean focus)
Informs the tag that it should render JavaScript to ensure that it is focused when the page is loaded. If the tag does not have an 'id' attribute a random one will be created and set so that the tag can be located easily.

Parameters:
focus - true if focus is desired, false otherwise

makeFocused

protected void makeFocused()
                    throws JspException
Writes out a JavaScript string to set focus on the field as it is rendered.

Throws:
JspException

doEndInputTag

public abstract int doEndInputTag()
                           throws JspException
Abstract method implemented in child classes instead of doEndTag().

Throws:
JspException

setDisabled

public void setDisabled(String disabled)
Checks to see if the value provided is either 'disabled' or a value that the BooleanTypeConverter believes it true. If so, adds a disabled attribute to the tag, otherwise does not.


getDisabled

public String getDisabled()

setReadonly

public void setReadonly(String readonly)

Sets the value of the readonly attribute to "readonly" but only when the value passed in is either "readonly" itself, or is converted to true by the BooleanTypeConverter.

Although not all input tags support the readonly attribute, the method is located here because it is not a simple one-liner and is used by more than one tag.


getReadonly

public String getReadonly()
Gets the HTML attribute of the same name.


setName

public void setName(String name)

getName

public String getName()

setSize

public void setSize(String size)

getSize

public String getSize()


? Copyright 2005-2006, Stripes Development Team.