net.sourceforge.stripes.tag
Class ErrorsTag

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

public class ErrorsTag
extends HtmlTagSupport
implements BodyTag

The errors tag has two modes, one where it displays all validation errors in a list and a second mode when there is a single enclosed field-error tag that has no name attribute in which case this tag iterates over the body, displaying each error in turn in place of the field-error tag.

In the first mode, where the default output is used, it is possible to change the output for the entire application using a set of resources in the error messages bundle (StripesResources.properties unless you have configured another). If the properties are undefined, the tag will output the text "Validation Errors" in a div with css class errorHeader, then output an unordered list of error messages. The following four resource strings (shown with their default values) can be modified to create different default ouput:

This tag has several ways of being attached to the errors of a specific action request. If the tag is inside a action tag, it will display if the validation errors are associated with that action. If supplied a name attribute, it will display errors only if the name attribute matches the name of the submitted action. Finally, if neither is the case, it will always display as described in the paragraph above.

Author:
Greg Hinkle

Field Summary
static String DEFAULT_FOOTER
          The footer that will be emitted if no footer is defined in the resource bundle.
static String DEFAULT_HEADER
          The header that will be emitted if no header is defined in the resource bundle.
 
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
ErrorsTag()
           
 
Method Summary
 int doAfterBody()
          Manages iteration, running again if there are more errors to display.
 int doEndTag()
          Output the error list if this was an empty body tag and we're fully controlling output*
 void doInitBody()
          Sets the context variables for the current error and index
 int doStartTag()
          Determines if the tag should display errors based on the action that it is displaying for, and then fetches the appropriate list of errors and makes sure it is non-empty.
 String getAction()
          Returns the value set with setAction().
protected  ActionBean getActionBean()
          Fetches the ActionBean associated with the action if one is present.
 ValidationError getCurrentError()
          Called by the IndividualErrorTag to fetch the current error from the set being iterated.
 String getField()
          Gets the value set with setField().
 boolean isFirst()
          Returns true if the error displayed is the first matching error.
 boolean isLast()
          Returns true if the error displayed is the last matching error.
 void setAction(String action)
          Sets the (optional) action of the form to display errors for, if they exist.
 void setField(String field)
          Sets the (optional) name of a field to display errors for, if errors exist.
 
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.BodyTag
setBodyContent
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, release, setPageContext, setParent
 

Field Detail

DEFAULT_HEADER

public static final String DEFAULT_HEADER
The header that will be emitted if no header is defined in the resource bundle.

See Also:
Constant Field Values

DEFAULT_FOOTER

public static final String DEFAULT_FOOTER
The footer that will be emitted if no footer is defined in the resource bundle.

See Also:
Constant Field Values
Constructor Detail

ErrorsTag

public ErrorsTag()
Method Detail

getCurrentError

public ValidationError getCurrentError()
Called by the IndividualErrorTag to fetch the current error from the set being iterated.

Returns:
The error displayed for this iteration of the errors tag

isFirst

public boolean isFirst()
Returns true if the error displayed is the first matching error.


isLast

public boolean isLast()
Returns true if the error displayed is the last matching error.


setAction

public void setAction(String action)
Sets the (optional) action of the form to display errors for, if they exist.


getAction

public String getAction()
Returns the value set with setAction().


setField

public void setField(String field)
Sets the (optional) name of a field to display errors for, if errors exist.


getField

public String getField()
Gets the value set with setField().


doStartTag

public int doStartTag()
               throws JspException
Determines if the tag should display errors based on the action that it is displaying for, and then fetches the appropriate list of errors and makes sure it is non-empty.

Specified by:
doStartTag in interface Tag
Specified by:
doStartTag in class StripesTagSupport
Returns:
SKIP_BODY if the errors are not to be output, or there aren't any
EVAL_BODY_TAG if there are errors to display
Throws:
JspException

doInitBody

public void doInitBody()
                throws JspException
Sets the context variables for the current error and index

Specified by:
doInitBody in interface BodyTag
Throws:
JspException

doAfterBody

public int doAfterBody()
                throws JspException
Manages iteration, running again if there are more errors to display. If there is no nested FieldError tag, will ensure that the body is evaluated only once.

Specified by:
doAfterBody in interface IterationTag
Returns:
EVAL_BODY_TAG if there are more errors to display, SKIP_BODY otherwise
Throws:
JspException

doEndTag

public int doEndTag()
             throws JspException
Output the error list if this was an empty body tag and we're fully controlling output*

Specified by:
doEndTag in interface Tag
Specified by:
doEndTag in class StripesTagSupport
Returns:
EVAL_PAGE always
Throws:
JspException

getActionBean

protected ActionBean getActionBean()
Fetches the ActionBean associated with the action 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 action 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 action if there is one


© Copyright 2005, Stripes Development Team.