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 FormConstructor and Description |
---|
SimpleError(java.lang.String message,
java.lang.Object... parameter)
Constructs a simple error message.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Generated equals method that ensures the message, field, parameters and action path are all equal.
|
java.lang.String |
getActionPath()
Provides subclasses access to the name of the form on which the errored field occurs.
|
java.lang.Class<? extends ActionBean> |
getBeanclass()
Returns the class of the ActionBean associated to the request.
|
java.lang.String |
getFieldName()
Provides subclasses access to the field name.
|
java.lang.String |
getFieldValue()
Provides subclasses with access to the value of the field that is in error.
|
java.lang.String |
getMessage(java.util.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(java.util.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(java.lang.String actionPath)
Sets the binding path of the ActionBean on which the errored field occurs.
|
void |
setBeanclass(java.lang.Class<? extends ActionBean> beanclass)
Sets the class of the ActionBean associated to the request.
|
void |
setFieldName(java.lang.String name)
Sets the name of the form field in error.
|
void |
setFieldValue(java.lang.String value)
Sets the value of the field that is in error.
|
getMessage, getMessageTemplate, getReplacementParameters
public SimpleError(java.lang.String message, java.lang.Object... parameter)
message
- the String message (template) to displayparameter
- zero or more parameters for replacement into the messagepublic java.lang.String getMessage(java.util.Locale locale)
getMessage
in interface Message
getMessage
in class SimpleMessage
locale
- the locale of the current requestprotected void resolveFieldName(java.util.Locale locale)
public void setFieldName(java.lang.String name)
setFieldName
in interface ValidationError
public java.lang.String getFieldName()
getFieldName
in interface ValidationError
public void setFieldValue(java.lang.String value)
setFieldValue
in interface ValidationError
public java.lang.String getFieldValue()
getFieldValue
in interface ValidationError
public void setActionPath(java.lang.String actionPath)
setActionPath
in interface ValidationError
public java.lang.String getActionPath()
getActionPath
in interface ValidationError
public java.lang.Class<? extends ActionBean> getBeanclass()
getBeanclass
in interface ValidationError
public void setBeanclass(java.lang.Class<? extends ActionBean> beanclass)
setBeanclass
in interface ValidationError
public boolean equals(java.lang.Object o)
equals
in class SimpleMessage
o
- another object that is a SimpleMessage or subclass thereofpublic int hashCode()
hashCode
in class SimpleMessage
? Copyright 2005-2006, Stripes Development Team.