public class ErrorsTag extends HtmlTagSupport implements javax.servlet.jsp.tagext.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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_FOOTER
The footer that will be emitted if no footer is defined in the resource bundle.
|
static java.lang.String |
DEFAULT_HEADER
The header that will be emitted if no header is defined in the resource bundle.
|
pageContext, parentTag
Constructor and Description |
---|
ErrorsTag() |
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.String |
getAction()
Returns the value set with setAction().
|
ValidationError |
getCurrentError()
Called by the IndividualErrorTag to fetch the current error from the set being iterated.
|
java.lang.String |
getField()
Gets the value set with setField().
|
protected java.lang.String |
getResource(java.util.ResourceBundle bundle,
java.lang.String name,
java.lang.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(java.lang.String action)
Sets the (optional) action of the form to display errors for, if they exist.
|
void |
setBeanclass(java.lang.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(java.lang.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.
|
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
getActionBeanType, getActionBeanUrl, getPageContext, getParent, getParentTag, getTagStack, popPageContextAttributes, pushPageContextAttributes, setPageContext, setParent
public static final java.lang.String DEFAULT_HEADER
public static final java.lang.String DEFAULT_FOOTER
public ValidationError getCurrentError()
public boolean isFirst()
public boolean isLast()
public void setAction(java.lang.String action)
public java.lang.String getAction()
public void setBeanclass(java.lang.Object beanclass) throws StripesJspException
beanclass
- the FQN of an ActionBean class, or a Class object for one.StripesJspException
public void setField(java.lang.String field)
public java.lang.String getField()
public boolean isGlobalErrorsOnly()
public void setGlobalErrorsOnly(boolean globalErrorsOnly)
public int doStartTag() throws javax.servlet.jsp.JspException
doStartTag
in interface javax.servlet.jsp.tagext.Tag
doStartTag
in class StripesTagSupport
javax.servlet.jsp.JspException
public void doInitBody() throws javax.servlet.jsp.JspException
doInitBody
in interface javax.servlet.jsp.tagext.BodyTag
javax.servlet.jsp.JspException
public int doAfterBody() throws javax.servlet.jsp.JspException
doAfterBody
in interface javax.servlet.jsp.tagext.IterationTag
javax.servlet.jsp.JspException
public int doEndTag() throws javax.servlet.jsp.JspException
doEndTag
in interface javax.servlet.jsp.tagext.Tag
doEndTag
in class StripesTagSupport
javax.servlet.jsp.JspException
protected java.lang.String getResource(java.util.ResourceBundle bundle, java.lang.String name, java.lang.String fallback)
bundle
- the bundle to look up the resource fromname
- the name of the resource to lookup (prefixes will be added)fallback
- a value to return if no resource can be found? Copyright 2005-2006, Stripes Development Team.