Class MvcMessage

java.lang.Object
de.chkal.mvctoolbox.core.message.MvcMessage
All Implemented Interfaces:
Serializable

public class MvcMessage extends Object implements Serializable
Represents a single message which is meant to be displayed to the user. Every message consists of a human readable text and a severity. Optionally a message can be associated with a parameter. This is typically useful for validation errors which always relate to a specific parameter. If the message is not associated with a parameter, the message is called a global message.
Author:
Christian Kaltepoth
See Also:
  • Constructor Details

    • MvcMessage

      public MvcMessage(String text)
      Creates a new global message with a severity of INFO.
      Parameters:
      text - The text of the message, must not be null
    • MvcMessage

      public MvcMessage(MvcMessage.Severity severity, String text)
      Creates a new global message with the given severity.
      Parameters:
      severity - The severity of the message, must not be null
      text - The text of the message, must not be null
    • MvcMessage

      public MvcMessage(MvcMessage.Severity severity, String param, String text)
      Creates a new message referring to the given parameter.
      Parameters:
      severity - The severity of the message, must not be null
      param - The name of parameter this message refers to or null
      text - The text of the message, must not be null
  • Method Details

    • info

      public static MvcMessage info(String text)
      Creates a new global info message.
      Parameters:
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • info

      public static MvcMessage info(String param, String text)
      Creates a new info message referring to the given parameter.
      Parameters:
      param - The name of parameter this message refers to or null
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • warning

      public static MvcMessage warning(String text)
      Creates a new global warning message.
      Parameters:
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • warning

      public static MvcMessage warning(String param, String text)
      Creates a new warning message referring to the given parameter.
      Parameters:
      param - The name of parameter this message refers to or null
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • error

      public static MvcMessage error(String text)
      Creates a new global error message.
      Parameters:
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • error

      public static MvcMessage error(String param, String text)
      Creates a new error message referring to the given parameter.
      Parameters:
      param - The name of parameter this message refers to or null
      text - The text of the message, must not be null
      Returns:
      a new MvcMessage instance
    • getSeverity

      public MvcMessage.Severity getSeverity()
      Returns the severity of of the message
      Returns:
      the severity of the message
    • getParam

      public String getParam()
      Returns the parameter the message is associated with or null for global messages
      Returns:
      the parameter or null
    • getText

      public String getText()
      Returns the text of the message
      Returns:
      the text of the message
    • isGlobal

      public boolean isGlobal()
      Returns true for global messages which is equivalent to param being null.
      Returns:
      whether or not the message is global