|
Version 4.10.0
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Objecthirondelle.web4j.model.AppResponseMessage
public final class AppResponseMessage
Informative message presented to the end user.
This class exists in order to hide the difference between simple and compound messages.
Simple Messages
Simple messages are a single String, such as 'Item deleted successfully.'.
They are created using forSimple(String).
Compound Messages
Compound messages are made up of several parts, and have parameters. They are created
using forCompound(String, Object...). A compound message
is usually implemented in Java using MessageFormat.
However, MessageFormat is not used by this class, to avoid the following issues :
MessageFormat is rather complicated in its details.
Format of Compound Messages
This class defines an alternative format to that defined by MessageFormat.
For example,
"At this restaurant, the _1_ meal costs _2_." "On _2_, I am going to Manon's place to see _1_."Here,
Formats.
If the default formatting applied by Formats is not desired, then the caller
can always manually format the parameter as a String. (The Translator may be used when
a different pattern is needed for different Locales.)
Multilingual Applications
Multilingual applications will need to ensure that messages can be successfully translated when
presented in JSPs. In particular, some care must be exercised to not create
a simple message out of various pieces of data when a compound message
should be used instead. See getMessage(Locale, TimeZone).
As well, see the hirondelle.web4j.ui.translate
package for more information, in particular the
Messages tag used for rendering AppResponseMessages,
even in single language applications.
Serialization
This class implements Serializable to allow messages stored in session scope to
be transferred over a network, and thus survive a failover operation.
However, this class's implementation of Serializable interface has a minor defect.
This class accepts Objects as parameters to messages. These objects almost always represent
data - String, Integer, Id, DateTime, and so on, and all such building block classes are Serializable.
If, however, the caller passes an unusual message parameter object which is not Serializable, then the
serialization of this object (if it occurs), will fail.
The above defect will likely not be fixed since it has large ripple effects, and would seem to cause
more problems than it would solve. In retrospect, this the message parameters passed to
forCompound(String, Object[]) should likely have been typed as Serializable, not Object.
| Method Summary | |
|---|---|
boolean |
equals(Object aThat)
|
static AppResponseMessage |
forCompound(String aPattern,
Object... aParams)
Compound message having parameters. |
static AppResponseMessage |
forSimple(String aSimpleText)
Simple message having no parameters. |
String |
getMessage(Locale aLocale,
TimeZone aTimeZone)
Return either the 'simple text' or the formatted pattern with all parameter data rendered, according to which factory method was called. |
List<Object> |
getParams()
Return an unmodifiable List corresponding to the aParams passed to the constructor. |
int |
hashCode()
|
String |
toString()
Return either the 'simple text' or the pattern, according to which factory method was called. |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static AppResponseMessage forSimple(String aSimpleText)
public static AppResponseMessage forCompound(String aPattern,
Object... aParams)
aPattern follows the custom format defined by this class.
Formats.objectToTextForReport(java.lang.Object) will be used to format all parameters.
aPattern - must be in the style of the custom format, and
the number of placeholders must match the number of items in aParams.aParams - must have at least one member; all members must be non-null, but may be empty
Strings.
public String getMessage(Locale aLocale,
TimeZone aTimeZone)
The configured Translator is used to localize
forSimple(String)
forCompound(String, Object...)
RequestParameter parameters passed to forCompound(String, Object...)
are localized by using Translator on the return value of RequestParameter.getName()
(This is intended for displaying localized versions of control names.)
It is highly recommended that this method be called late in processing, in a JSP.
The Locale should almost always come from
BuildImpl.forLocaleSource().
The aLocale parameter is always required, even though there are cases when it
is not actually used to render the result.
public List<Object> getParams()
If no parameters are being used, then return an empty list.
public String toString()
getMessage(java.util.Locale, java.util.TimeZone)).
toString in class Objectpublic boolean equals(Object aThat)
equals in class Objectpublic int hashCode()
hashCode in class Object
|
Version 4.10.0
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||