-
Notifications
You must be signed in to change notification settings - Fork 17
WMessages
WMessages is the component used to add each message to a WMessageBox.
- Using WMessages
- Arrangement of messages
- WPanel properties
- Accessing a message box
- HTML output
- Related Components
- Further information
Feedback messages are displayed as needed by adding a WMessages component to a UI. This is then used to display WMessageBox components if any messages are to be shown to the user.
WMessages messages = new WMessages();
add(messages);
//.. then add messages as required.
// present a message in an information box.
messages.info("This is an information message");
Messages are added according to their severity (or type) as error
, warn
, info
or success
.
// given WMessages messages
// present a message in an error box.
messages.error("Oh dear we have messed it up.");
// present a message in a warning box.
messages.warn("You really oughtn't do that.");
// present a message in an information box.
messages.info("Tea; Earl Grey; hot.");
// present a message in a success box.
messages.success("Huzzah! Jolly good show.");
Messages are HTML escaped by default but may have unescaped content.
// given WMessages messages
messages.info("¿Que?", false);
If all messages are of the same severity then they are displayed in a single message box of the relevant type. If a WMessages has messages of different types then a message box is shown for each type. In this case the WMessages may use a WPanel Layout (such as FlowLayout) to arrange the message boxes.
WMessages messages = new WMessages();
messages.setLayout(new FlowLayout(FlowLayout.Alignment.VERTICAL, 12));
WMessages extends WPanel. Therefore many of the WPanel properties may be applied to WMessages. It is strongly recommended that most be avoided and that the WPanel Type
is never set: the output of WMessages appears to be wrapped in a WPanel and setting the Type
may have unexpected results.
The WMessages may have a Layout (see arrangement of messages) and a Margin. All other options are best avoided.
WMessages holds a reference to a WMessageBox for each type of message added. This can be used to get a handle to the WMessageBox if required.
// get the Error box
WMessageBox errorBox = messages.getErrorMessageBox();
// get the Warning box
WMessageBox warningBox = messages.getWarningMessageBox();
// get the Info box
WMessageBox infoBox = messages.getInfoMessageBox();
// get the Error box
WMessageBox successBox = messages.getSuccessMessageBox();
This could be used to manipulate the message box as WMessageBox may be a target for WSubordinateControl or WAjaxControl. One must use WMessageBox to remove individual messages from WMessages. All messages may be removed simply by resetting WMessages.
WMessages outputs a HTML section element wrapper for each type of message added to it (see WMessageBox) and, for each message, a div element. A message may contain any other component and may contain unescaped content.
The WMessageBox wrappers are themselves in a WPanel.