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, DynamicAttributes, 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 output:

The errors tag can also be used to display errors for a single field by supplying it with a 'field' attribute which matches the name of a field on the page. In this case the tag will display only if errors exist for the named field. In this mode the tag will first look for resources named:

If the fieldErrors resources cannot be found, the tag will default to using the same resources and defaults as when displaying for all fields.

Similar to the above, field specific, manner of display the errors tag can also be used to output only errors not associated with a field, i.e. global errors. This is done by setting the globalErrorsOnly attribute to true.

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

Author:
Greg Hinkle, Tim Fennell

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().
 ValidationError getCurrentError()
          Called by the IndividualErrorTag to fetch the current error from the set being iterated.
 String getField()
          Gets the value set with setField().
protected  String getResource(ResourceBundle bundle, String name, String fallback)
          Utility method that is used to lookup the resources used for the errors header, footer, and the strings that go before and after each error.
 boolean isFirst()
          Returns true if the error displayed is the first matching error.
 boolean isGlobalErrorsOnly()
          Indicated whether the tag is displaying only global errors.
 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 setBeanclass(Object beanclass)
          Sets the action attribute by figuring out what ActionBean class is identified and then in turn finding out the appropriate URL for the ActionBean.
 void setField(String field)
          Sets the (optional) name of a field to display errors for, if errors exist.
 void setGlobalErrorsOnly(boolean globalErrorsOnly)
          Tells the tag to display (or not) only global errors and no field level errors.
 
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
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().


setBeanclass

public void setBeanclass(Object beanclass)
                  throws StripesJspException
Sets the action attribute by figuring out what ActionBean class is identified and then in turn finding out the appropriate URL for the ActionBean.

Parameters:
beanclass - the FQN of an ActionBean class, or a Class object for one.
Throws:
StripesJspException

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().


isGlobalErrorsOnly

public boolean isGlobalErrorsOnly()
Indicated whether the tag is displaying only global errors.


setGlobalErrorsOnly

public void setGlobalErrorsOnly(boolean globalErrorsOnly)
Tells the tag to display (or not) only global errors and no field level errors.


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

getResource

protected String getResource(ResourceBundle bundle,
                             String name,
                             String fallback)
Utility method that is used to lookup the resources used for the errors header, footer, and the strings that go before and after each error.

Parameters:
bundle - the bundle to look up the resource from
name - the name of the resource to lookup (prefixes will be added)
fallback - a value to return if no resource can be found
Returns:
the value to use for the named resource


? Copyright 2005-2006, Stripes Development Team.