|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.action.SimpleMessage
net.sourceforge.stripes.validation.SimpleError
public class SimpleError
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 Summary | |
---|---|
SimpleError(String message,
Object... parameter)
Constructs a simple error message. |
Method Summary | |
---|---|
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. |
Methods inherited from class net.sourceforge.stripes.action.SimpleMessage |
---|
getMessage, getMessageTemplate, getReplacementParameters |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleError(String message, Object... parameter)
message
- the String message (template) to displayparameter
- zero or more parameters for replacement into the messageMethod Detail |
---|
public String getMessage(Locale locale)
getMessage
in interface Message
getMessage
in class SimpleMessage
locale
- the locale of the current request
protected void resolveFieldName(Locale locale)
public void setFieldName(String name)
setFieldName
in interface ValidationError
public String getFieldName()
getFieldName
in interface ValidationError
public void setFieldValue(String value)
setFieldValue
in interface ValidationError
public String getFieldValue()
getFieldValue
in interface ValidationError
public void setActionPath(String actionPath)
setActionPath
in interface ValidationError
public String getActionPath()
getActionPath
in interface ValidationError
public Class<? extends ActionBean> getBeanclass()
getBeanclass
in interface ValidationError
public void setBeanclass(Class<? extends ActionBean> beanclass)
setBeanclass
in interface ValidationError
public boolean equals(Object o)
equals
in class SimpleMessage
o
- another object that is a SimpleMessage or subclass thereof
public int hashCode()
hashCode
in class SimpleMessage
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |