public class SimpleMessage extends Object implements Message
A simple non-error message that uses the String supplied to it as the message (i.e. it does not look up the message in a resource bundle).
Messages may contain one or more "replacement parameters". To use replacement parameters a message must contain the replacement token {#} where # is the numeric index of the replacement parameter.
For example, to construct a message with two replacement parameters you might supply a message like:
Welcome back {0}, your last login was on {1,date,short}.
At runtime this might get replaced out to result in a message for the user that looks like "Welcome back Johnnie, your last login was on 01/01/2006".
MessageFormat is used to merge the parameters in to the message and as
a result the parameters can themselves receive formatting through the various java.text.*
formatters.
MessageFormat,
Serialized Form| Modifier | Constructor and Description |
|---|---|
protected |
SimpleMessage(Object... parameters)
Helper constructor to allow subclasses to provide and manipulate replacement
parameters without having to supply a message String.
|
|
SimpleMessage(String message,
Object... parameters)
Constructs a message with the supplied message string and zero or more parameters
to be merged into the message.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o)
Checks equality by ensuring that the current instance and the 'other' instance are
instances of the same class (though not necessarily SimpleMessage!) and that the
message String and replacement parameters provided are the same.
|
String |
getMessage()
Returns the exact message that was supplied in the constructor.
|
String |
getMessage(Locale locale)
Uses the String message passed in as the message template and combines it with any
replacement parameters provided to construct a message for display to the user.
|
protected String |
getMessageTemplate(Locale locale)
Simply returns the message passed in at Construction time.
|
Object[] |
getReplacementParameters()
Allows subclasses to access the replacement parameters for this message.
|
int |
hashCode()
Generated hash code method.
|
public SimpleMessage(String message, Object... parameters)
message - the String message to display to the user, optionally with placeholders
for replacement parametersparameters - protected SimpleMessage(Object... parameters)
parameters - zero or more parameters for replacement into the messagepublic String getMessage(Locale locale)
getMessage in interface Messagelocale - the locale of the current requestprotected String getMessageTemplate(Locale locale)
locale - the Locale of the message template desiredpublic String getMessage()
public Object[] getReplacementParameters()
public boolean equals(Object o)
© Copyright 2005-2006, Stripes Development Team.