Class WMessages
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.WContainer
-
- com.github.bordertech.wcomponents.WPanel
-
- com.github.bordertech.wcomponents.WMessages
-
- All Implemented Interfaces:
AccessKeyable
,AjaxInternalTrigger
,AjaxTarget
,BeanAware
,BeanBound
,BeanProviderBound
,Container
,DataBound
,DropZone
,Marginable
,MutableContainer
,NamingContextable
,SubordinateTarget
,WComponent
,WebComponent
,Serializable
public class WMessages extends WPanel
WMessages provides a convenient wrapper for the WMessageBox and WValidationErrors components, and lets the developer use a "singleton" WMessages instance per application.
- Since:
- 1.0.0
- Author:
- Yiannis Paschalidis, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.WPanel
WPanel.PanelMode, WPanel.PanelModel, WPanel.Type
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMessage(Message message)
Adds a message.void
addMessage(Message message, boolean encodeText)
Adds a message.void
error(String code)
Adds an error message.void
error(String code, boolean encodeText)
Adds an error message.void
error(String code, String field)
Adds an error message.void
error(String code, String field, boolean encodeText)
Adds an error message.WMessageBox
getErrorMessageBox()
List<String>
getErrorMessages()
WMessageBox
getInfoMessageBox()
List<String>
getInfoMessages()
static WMessages
getInstance(WComponent component)
Retrieves the WMessages instance for the given component.protected static MessageContainer
getMessageContainer(WComponent component)
Searches the WComponent tree of the given component for an ancestor that implements the MessageContainer interface.List<String>
getMessages(int type)
WMessageBox
getSuccessMessageBox()
List<String>
getSuccessMessages()
WValidationErrors
getValidationErrors()
WMessageBox
getWarningMessageBox()
List<String>
getWarningMessages()
boolean
hasMessages()
void
info(String code)
Adds an informational message.void
info(String code, boolean encodeText)
Adds an informational message.void
info(String code, String field)
Adds an informational message.void
info(String code, String field, boolean encodeText)
Adds an informational message.boolean
isHidden()
Indicates whether this component is hidden.void
success(String code)
Adds a success message.void
success(String code, boolean encodeText)
Adds a success message.void
success(String code, String field)
Adds a success message.void
success(String code, String field, boolean encodeText)
Adds a success message.void
warn(String code)
Adds a warning message.void
warn(String code, boolean encodeText)
Adds a warning message.void
warn(String code, String field)
Adds a warning message.void
warn(String code, String field, boolean encodeText)
Adds a warning message.-
Methods inherited from class com.github.bordertech.wcomponents.WPanel
add, add, getAccessKey, getComponentModel, getDefaultSubmitButton, getLayout, getLayoutConstraints, getMargin, getMode, getOrCreateComponentModel, getTitleText, getType, newComponentModel, remove, setAccessKey, setDefaultSubmitButton, setLayout, setMargin, setMode, setTitleText, setType, toString
-
Methods inherited from class com.github.bordertech.wcomponents.WContainer
add, add, getChildAt, getChildCount, getChildren, getIndexOfChild, getNamingContextId, isNamingContext, removeAll, setNamingContext, setTemplate, setTemplate, setTemplateMarkUp
-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, handleRequest, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.AccessKeyable
getAccessKeyAsString
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
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
tofalse
, 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 tofalse
may result in security issues.- Parameters:
message
- the message to addencodeText
- 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
tofalse
, 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 tofalse
may result in security issues.- Parameters:
code
- the message codeencodeText
- 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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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
tofalse
, 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 tofalse
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 interfaceWComponent
- Overrides:
isHidden
in classAbstractWComponent
- Returns:
true
if explicitly hidden or if the WMessages has no messages.
-
-