Class WMessageBox

  • All Implemented Interfaces:
    AjaxTarget, SubordinateTarget, WComponent, WebComponent, Serializable

    public class WMessageBox
    extends AbstractWComponent
    implements AjaxTarget, SubordinateTarget

    A WMessageBox is a component that renders a collection of informational messages. Most commonly placed near the top of an application's UI.

    The different message types catered for here are:

    • Error - For reporting system and application errors.
    • Warning - For warning users about the possible consequences of an action. The process may continue.
    • Information - For providing general information.
    • Success - For reporting on the success of an action or operation.

    NOTE: Validation errors should be provided via the component WValidationErrors.

    Author:
    Ming Gao, Adam Millard, Jonathan Austin, Mark Reeves
    See Also:
    WValidationErrors, WMessages, Serialized Form
    • Field Detail

      • SUCCESS

        public static final WMessageBox.Type SUCCESS
        The message box type used to display "success" messages.
      • INFO

        public static final WMessageBox.Type INFO
        The message box type used to display informational messages.
      • WARN

        public static final WMessageBox.Type WARN
        The message box type used to display warning messages.
      • ERROR

        public static final WMessageBox.Type ERROR
        The message box type used to display error messages.
    • Constructor Detail

      • WMessageBox

        public WMessageBox​(WMessageBox.Type type,
                           String msg,
                           Serializable... args)
        Creates a WMessageBox of the given type with an initial message.
        Parameters:
        type - the messageBox type, one of SUCCESS, INFO, WARN or ERROR.
        msg - the initial message to display, using MessageFormat syntax.
        args - optional arguments for the message format string.
      • WMessageBox

        public WMessageBox​(WMessageBox.Type type,
                           boolean encode,
                           String msg,
                           Serializable... args)
        Creates a WMessageBox of the given type with an initial message.
        Parameters:
        type - the messageBox type, one of SUCCESS, INFO, WARN or ERROR.
        encode - true to encode the message text, false to leave it unencoded.
        msg - the initial message to display, using MessageFormat syntax.
        args - optional arguments for the message format string.
    • Method Detail

      • getType

        public WMessageBox.Type getType()
        Returns:
        the message box type for the given context.
      • setTitleText

        public void setTitleText​(String title,
                                 Serializable... args)
        Sets the message box title.
        Parameters:
        title - the message box title to set, using MessageFormat syntax.
        args - optional arguments for the message format string.
      • getTitleText

        public String getTitleText()
        Returns:
        the message box title.
      • addMessage

        public void addMessage​(String msg,
                               Serializable... args)
        Adds a message to the message box.
        Parameters:
        msg - the text of the message to add, using MessageFormat syntax.
        args - optional arguments for the message format string.
      • addMessage

        public void addMessage​(boolean encode,
                               String msg,
                               Serializable... args)
        Adds a message to the message box.
        Parameters:
        encode - true to encode the message text, false to leave it unencoded.
        msg - the text of the message to add, using MessageFormat syntax.
        args - optional arguments for the message format string.
      • removeMessage

        public void removeMessage​(int index)
        Removes a message from the message box.
        Parameters:
        index - the index of the message to remove.
      • removeMessages

        public void removeMessages​(int index)
        Removes a message from the message box.
        Parameters:
        index - the index of the mssage to remove.
      • clearMessages

        public void clearMessages()
        Removes all messages from the message box.
      • getMessages

        public List<String> getMessages()
        Retrieves the list of messages.
        Returns:
        the messages for the current context.
      • hasMessages

        public boolean hasMessages()
        Indicates whether the message box contains messages in the given context.
        Returns:
        true if the message box contains at least one message.
      • toString

        public String toString()
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component.
      • getComponentModel

        protected WMessageBox.MessageModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class AbstractWComponent
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WMessageBox.MessageModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractWComponent
        Returns:
        the model for this component