Class WMessages

    • Constructor Detail

      • WMessages

        public WMessages()
        Creates a new WMessages, where only validation messages are persisted between requests.
      • WMessages

        public WMessages​(boolean persistent)
        Creates a new WMessages.
        Parameters:
        persistent - if true, all messages are persisted between requests. If false, only validation messages are persisted between requests.
    • Method Detail

      • getInstance

        public static WMessages getInstance​(WComponent component)
        Retrieves the WMessages instance for the given component. The component tree is searched for an ancestor that implements the MessageContainer interface. If not found, a proxy is returned that searches for the MessageContainer each time a WMessages method is called. This allows developers to obtain a valid "instance" during e.g. constructors, where the component will not have been added to the tree yet.
        Parameters:
        component - the component to retrieve the WMessages instance for
        Returns:
        the WMessages instance for the given component.
      • hasMessages

        public boolean hasMessages()
        Returns:
        true if there are messages to display
      • addMessage

        public void addMessage​(Message message)
        Adds a message.
        Parameters:
        message - the message to add
      • addMessage

        public void addMessage​(Message message,
                               boolean encodeText)
        Adds a message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        message - the message to add
        encodeText - true to encode the message, false to leave it unencoded.
      • success

        public void success​(String code)
        Adds a success message.
        Parameters:
        code - the message code
      • success

        public void success​(String code,
                            boolean encodeText)
        Adds a success message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code
        encodeText - true to encode the message, false otherwise.
      • success

        public void success​(String code,
                            String field)
        Adds a success message.
        Parameters:
        code - the message code.
        field - the field for the success message.
      • success

        public void success​(String code,
                            String field,
                            boolean encodeText)
        Adds a success message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        field - the field for the success message.
        encodeText - true to encode the message, false otherwise.
      • info

        public void info​(String code)
        Adds an informational message.
        Parameters:
        code - the message code.
      • info

        public void info​(String code,
                         boolean encodeText)
        Adds an informational message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        encodeText - true to encode the message, false otherwise.
      • info

        public void info​(String code,
                         String field)
        Adds an informational message.
        Parameters:
        code - the message code.
        field - the field for the information message.
      • info

        public void info​(String code,
                         String field,
                         boolean encodeText)
        Adds an informational message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        field - the field for the information message.
        encodeText - true to encode the message, false otherwise.
      • warn

        public void warn​(String code)
        Adds a warning message.
        Parameters:
        code - the message code.
      • warn

        public void warn​(String code,
                         boolean encodeText)
        Adds a warning message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        encodeText - true to encode the message, false otherwise.
      • warn

        public void warn​(String code,
                         String field)
        Adds a warning message.
        Parameters:
        code - the message code.
        field - the field for the information message.
      • warn

        public void warn​(String code,
                         String field,
                         boolean encodeText)
        Adds a warning message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        field - the field for the information message.
        encodeText - true to encode the message, false otherwise.
      • error

        public void error​(String code)
        Adds an error message.
        Parameters:
        code - the message code.
      • error

        public void error​(String code,
                          boolean encodeText)
        Adds an error message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        encodeText - true to encode the message, false otherwise.
      • error

        public void error​(String code,
                          String field)
        Adds an error message.
        Parameters:
        code - the message code.
        field - the field for the information message.
      • error

        public void error​(String code,
                          String field,
                          boolean encodeText)
        Adds an error message.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WMessageBox to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        Parameters:
        code - the message code.
        field - the field for the information message.
        encodeText - true to encode the message, false otherwise.
      • getInfoMessages

        public List<String> getInfoMessages()
        Returns:
        all informational messages for this Messages instance.
      • getWarningMessages

        public List<String> getWarningMessages()
        Returns:
        all warning messages for this Messages instance.
      • getErrorMessages

        public List<String> getErrorMessages()
        Returns:
        all error messages for this Messages instance.
      • getSuccessMessages

        public List<String> getSuccessMessages()
        Returns:
        all success messages for this Messages instance.
      • getMessages

        public List<String> getMessages​(int type)
        Parameters:
        type - the message type (@see Message)
        Returns:
        all messages of the given type for this Messages instance.
      • getValidationErrors

        public WValidationErrors getValidationErrors()
        Returns:
        the validation errors component, for use in e.g. ValidatingActions.
      • getSuccessMessageBox

        public WMessageBox getSuccessMessageBox()
        Returns:
        the success message box.
      • getWarningMessageBox

        public WMessageBox getWarningMessageBox()
        Returns:
        the warning message box.
      • getErrorMessageBox

        public WMessageBox getErrorMessageBox()
        Returns:
        the error message box.
      • getInfoMessageBox

        public WMessageBox getInfoMessageBox()
        Returns:
        the info message box.
      • getMessageContainer

        protected static MessageContainer getMessageContainer​(WComponent component)
        Searches the WComponent tree of the given component for an ancestor that implements the MessageContainer interface.
        Parameters:
        component - the component to return the Container for
        Returns:
        the nearest MessageContainer if found, null otherwise
      • isHidden

        public boolean isHidden()
        Description copied from class: AbstractWComponent
        Indicates whether this component is hidden. Hidden components take part in event handling and painting, but are not visible on the client.
        Specified by:
        isHidden in interface WComponent
        Overrides:
        isHidden in class AbstractWComponent
        Returns:
        true if explicitly hidden or if the WMessages has no messages.