public class SimpleError extends SimpleMessage implements ValidationError
Validation error message that allows for supplying the error message at the time of creation - i.e. not through a resource bundle or other external mechanism. SimpleError will still attempt to lookup the field name in the field name bundle, but as with other errors, it will fall back to a prettified version of the field name that is used in the input tag.
Messages may contain one or more "replacement parameters". Two replacement parameters are provided by default, they are the field name and field value, and are indices 0 and 1 respectively. To use replacement parameters a message must contain the replacement token {#} where # is the numeric index of the replacement parameter.
For example, to construct an error message with one additional replacement parameter which is the action the user was trying to perform, you might supply a message like:
{1} is not a valid {0} when trying to {2}
At runtime this might get replaced out to result in an error message for the user that looks like "Fixed is not a valid status when trying to create a new bug".
One last point of interest is where the user friendly field name comes from. Firstly an attempt is made to look up the localized name in the applicable resource bundle using the String beanClassFQN.fieldName where beanClassFQN is the fully qualified name of the bean class, and fieldName is the name of the field on the form. The second attempt is made with String actionPath.fieldName where actionPath is the action of the form in the JSP (or equally, the path given in the @UrlBinding annotation in the ActionBean class). Finally, the last attempt uses fieldName by itself.
MessageFormat,
Serialized Form| Constructor and Description |
|---|
SimpleError(String message,
Object... parameter)
Constructs a simple error message.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o)
Generated equals method that ensures the message, field, parameters and action path are all equal.
|
String |
getActionPath()
Provides subclasses access to the name of the form on which the errored field occurs.
|
Class<? extends ActionBean> |
getBeanclass()
Returns the class of the ActionBean associated to the request.
|
String |
getFieldName()
Provides subclasses access to the field name.
|
String |
getFieldValue()
Provides subclasses with access to the value of the field that is in error.
|
String |
getMessage(Locale locale)
Looks up the field name in the resource bundle (if it exists) so that it can be used
in the message, and then defers to it's super class to combine the message template
with the replacement parameters provided.
|
int |
hashCode()
Hash code based on the message, field name key, action path and parameters.
|
protected void |
resolveFieldName(Locale locale)
Takes the form field name supplied and tries first to resolve a String in the locale
specific bundle for the field name, and if that fails, will try to make a semi-friendly
name by parsing the form field name.
|
void |
setActionPath(String actionPath)
Sets the binding path of the ActionBean on which the errored field occurs.
|
void |
setBeanclass(Class<? extends ActionBean> beanclass)
Sets the class of the ActionBean associated to the request.
|
void |
setFieldName(String name)
Sets the name of the form field in error.
|
void |
setFieldValue(String value)
Sets the value of the field that is in error.
|
getMessage, getMessageTemplate, getReplacementParameterspublic String getMessage(Locale locale)
getMessage in interface MessagegetMessage in class SimpleMessagelocale - the locale of the current requestprotected void resolveFieldName(Locale locale)
public void setFieldName(String name)
setFieldName in interface ValidationErrorpublic String getFieldName()
getFieldName in interface ValidationErrorpublic void setFieldValue(String value)
setFieldValue in interface ValidationErrorpublic String getFieldValue()
getFieldValue in interface ValidationErrorpublic void setActionPath(String actionPath)
setActionPath in interface ValidationErrorpublic String getActionPath()
getActionPath in interface ValidationErrorpublic Class<? extends ActionBean> getBeanclass()
getBeanclass in interface ValidationErrorpublic void setBeanclass(Class<? extends ActionBean> beanclass)
setBeanclass in interface ValidationErrorpublic boolean equals(Object o)
equals in class SimpleMessageo - another object that is a SimpleMessage or subclass thereofpublic int hashCode()
hashCode in class SimpleMessage© Copyright 2005-2006, Stripes Development Team.