Package com.vaadin.ui
Class Notification
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.Notification
-
- All Implemented Interfaces:
MethodEventSource,ClientConnector,Extension,Connector,Serializable
public class Notification extends AbstractExtension
A notification message, used to display temporary messages to the user - for example "Document saved", or "Save failed".The notification message can consist of several parts: caption, description and icon. It is usually used with only caption - one should be wary of filling the notification with too much information.
The notification message tries to be as unobtrusive as possible, while still drawing needed attention. There are several basic types of messages that can be used in different situations:- TYPE_HUMANIZED_MESSAGE fades away quickly as soon as the user uses the mouse or types something. It can be used to show fairly unimportant messages, such as feedback that an operation succeeded ("Document Saved") - the kind of messages the user ignores once the application is familiar.
- TYPE_WARNING_MESSAGE is shown for a short while after the user uses the mouse or types something. It's default style is also more noticeable than the humanized message. It can be used for messages that do not contain a lot of important information, but should be noticed by the user. Despite the name, it does not have to be a warning, but can be used instead of the humanized message whenever you want to make the message a little more noticeable.
- TYPE_ERROR_MESSAGE requires to user to click it before disappearing, and can be used for critical messages.
- TYPE_TRAY_NOTIFICATION is shown for a while in the lower right corner of the window, and can be used for "convenience notifications" that do not have to be noticed immediately, and should not interfere with the current task - for instance to show "You have a new message in your inbox" while the user is working in some other area of the application.
In addition to the basic pre-configured types, a Notification can also be configured to show up in a custom position, for a specified time (or until clicked), and with a custom stylename. An icon can also be added.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNotification.CloseEventEvent fired when a notification is closed.static interfaceNotification.CloseListenerAn interface used for listening to Notification close events.static classNotification.Type-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
-
Field Summary
Fields Modifier and Type Field Description static intDELAY_FOREVERstatic intDELAY_NONEstatic PositionPOSITION_BOTTOM_LEFTDeprecated.static PositionPOSITION_BOTTOM_RIGHTDeprecated.static PositionPOSITION_CENTEREDDeprecated.static PositionPOSITION_CENTERED_BOTTOMDeprecated.static PositionPOSITION_CENTERED_TOPDeprecated.static PositionPOSITION_TOP_LEFTDeprecated.static PositionPOSITION_TOP_RIGHTDeprecated.static Notification.TypeTYPE_ERROR_MESSAGEDeprecated.static Notification.TypeTYPE_HUMANIZED_MESSAGEDeprecated.static Notification.TypeTYPE_TRAY_NOTIFICATIONDeprecated.static Notification.TypeTYPE_WARNING_MESSAGEDeprecated.
-
Constructor Summary
Constructors Constructor Description Notification(String caption)Creates a "humanized" notification message.Notification(String caption, Notification.Type type)Creates a notification message of the specified type.Notification(String caption, String description)Creates a "humanized" notification message with a bigger caption and smaller description.Notification(String caption, String description, Notification.Type type)Creates a notification message of the specified type, with a bigger caption and smaller description.Notification(String caption, String description, Notification.Type type, boolean htmlContentAllowed)Creates a notification message of the specified type, with a bigger caption and smaller description.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddCloseListener(Notification.CloseListener listener)Adds a CloseListener to the Notification.voidclose()Closes (hides) the notification.protected voidclose(boolean userOriginated)Closes (hides) the notification.StringgetCaption()Gets the caption part of the notification message.intgetDelayMsec()Gets the delay before the notification disappears.StringgetDescription()Gets the description part of the notification message.ResourcegetIcon()Gets the icon part of the notification message.PositiongetPosition()Gets the position of the notification message.protected NotificationStategetState()Returns the shared state for this connector.protected NotificationStategetState(boolean markAsDirty)Returns the shared state for this connector.StringgetStyleName()Gets the style name for the notification message.booleanisHtmlContentAllowed()Checks whether caption and description are interpreted as HTML or plain text.voidsetCaption(String caption)Sets the caption part of the notification message.voidsetDelayMsec(int delayMsec)Sets the delay before the notification disappears.voidsetDescription(String description)Sets the description part of the notification message.voidsetHtmlContentAllowed(boolean htmlContentAllowed)Sets whether html is allowed in the caption and description.voidsetIcon(Resource icon)Sets the icon part of the notification message.voidsetPosition(Position position)Sets the position of the notification message.voidsetStyleName(String styleName)Sets the style name for the notification message.voidshow(Page page)Shows this notification on a Page.static Notificationshow(String caption)Shows a notification message on the middle of the current page.static Notificationshow(String caption, Notification.Type type)Shows a notification message the current page.static Notificationshow(String caption, String description, Notification.Type type)Shows a notification message the current page.-
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getParent, getSupportedParentType, remove, setParent
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
-
-
-
Field Detail
-
TYPE_HUMANIZED_MESSAGE
@Deprecated public static final Notification.Type TYPE_HUMANIZED_MESSAGE
Deprecated.
-
TYPE_WARNING_MESSAGE
@Deprecated public static final Notification.Type TYPE_WARNING_MESSAGE
Deprecated.
-
TYPE_ERROR_MESSAGE
@Deprecated public static final Notification.Type TYPE_ERROR_MESSAGE
Deprecated.
-
TYPE_TRAY_NOTIFICATION
@Deprecated public static final Notification.Type TYPE_TRAY_NOTIFICATION
Deprecated.
-
POSITION_CENTERED
@Deprecated public static final Position POSITION_CENTERED
Deprecated.
-
POSITION_CENTERED_TOP
@Deprecated public static final Position POSITION_CENTERED_TOP
Deprecated.
-
POSITION_CENTERED_BOTTOM
@Deprecated public static final Position POSITION_CENTERED_BOTTOM
Deprecated.
-
POSITION_TOP_LEFT
@Deprecated public static final Position POSITION_TOP_LEFT
Deprecated.
-
POSITION_TOP_RIGHT
@Deprecated public static final Position POSITION_TOP_RIGHT
Deprecated.
-
POSITION_BOTTOM_LEFT
@Deprecated public static final Position POSITION_BOTTOM_LEFT
Deprecated.
-
POSITION_BOTTOM_RIGHT
@Deprecated public static final Position POSITION_BOTTOM_RIGHT
Deprecated.
-
DELAY_FOREVER
public static final int DELAY_FOREVER
- See Also:
- Constant Field Values
-
DELAY_NONE
public static final int DELAY_NONE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Notification
public Notification(String caption)
Creates a "humanized" notification message. The caption is rendered as plain text with HTML automatically escaped.- Parameters:
caption- The message to show
-
Notification
public Notification(String caption, Notification.Type type)
Creates a notification message of the specified type. The caption is rendered as plain text with HTML automatically escaped.- Parameters:
caption- The message to showtype- The type of message
-
Notification
public Notification(String caption, String description)
Creates a "humanized" notification message with a bigger caption and smaller description. The caption and description are rendered as plain text with HTML automatically escaped.- Parameters:
caption- The message captiondescription- The message description
-
Notification
public Notification(String caption, String description, Notification.Type type)
Creates a notification message of the specified type, with a bigger caption and smaller description. The caption and description are rendered as plain text with HTML automatically escaped.- Parameters:
caption- The message captiondescription- The message descriptiontype- The type of message
-
Notification
public Notification(String caption, String description, Notification.Type type, boolean htmlContentAllowed)
Creates a notification message of the specified type, with a bigger caption and smaller description. Care should be taken to to avoid XSS vulnerabilities if html is allowed.- Parameters:
caption- The message captiondescription- The message descriptiontype- The type of messagehtmlContentAllowed- Whether html in the caption and description should be displayed as html or as plain text
-
-
Method Detail
-
getCaption
public String getCaption()
Gets the caption part of the notification message.- Returns:
- The message caption
-
setCaption
public void setCaption(String caption)
Sets the caption part of the notification message.- Parameters:
caption- The message caption
-
getDescription
public String getDescription()
Gets the description part of the notification message.- Returns:
- The message description
-
setDescription
public void setDescription(String description)
Sets the description part of the notification message.- Parameters:
description- The message description
-
getPosition
public Position getPosition()
Gets the position of the notification message.- Returns:
- The position
-
setPosition
public void setPosition(Position position)
Sets the position of the notification message.- Parameters:
position- The desired notification position, notnull
-
getIcon
public Resource getIcon()
Gets the icon part of the notification message.- Returns:
- The message icon
-
setIcon
public void setIcon(Resource icon)
Sets the icon part of the notification message.- Parameters:
icon- The desired message icon
-
getDelayMsec
public int getDelayMsec()
Gets the delay before the notification disappears.- Returns:
- the delay in milliseconds, -1 indicates the message has to be clicked.
-
setDelayMsec
public void setDelayMsec(int delayMsec)
Sets the delay before the notification disappears.- Parameters:
delayMsec- the desired delay in milliseconds, -1 to require the user to click the message
-
setStyleName
public void setStyleName(String styleName)
Sets the style name for the notification message.- Parameters:
styleName- The desired style name
-
getStyleName
public String getStyleName()
Gets the style name for the notification message.- Returns:
- The style name
-
setHtmlContentAllowed
public void setHtmlContentAllowed(boolean htmlContentAllowed)
Sets whether html is allowed in the caption and description. If set to true, the texts are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the texts are passed to the browser as plain text.- Parameters:
htmlContentAllowed- true if the texts are used as html, false if used as plain text
-
isHtmlContentAllowed
public boolean isHtmlContentAllowed()
Checks whether caption and description are interpreted as HTML or plain text.- Returns:
trueif the texts are used as HTML,falseif used as plain text- See Also:
setHtmlContentAllowed(boolean)
-
show
public void show(Page page)
Shows this notification on a Page.- Parameters:
page- The page on which the notification should be shown
-
close
public void close()
Closes (hides) the notification.If the notification is not shown, does nothing.
- Since:
- 8.4
-
close
protected void close(boolean userOriginated)
Closes (hides) the notification.If the notification is not shown, does nothing.
- Parameters:
userOriginated-trueif the notification was closed because the user clicked on it,falseif the notification was closed from the server- Since:
- 8.4
-
getState
protected NotificationState getState()
Description copied from class:AbstractClientConnectorReturns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use
getState(false)to avoid marking the connector as dirty.- Overrides:
getStatein classAbstractClientConnector- Returns:
- The shared state for this connector. Never null.
-
getState
protected NotificationState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractClientConnector- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
show
public static Notification show(String caption)
Shows a notification message on the middle of the current page. The message automatically disappears ("humanized message"). The caption is rendered as plain text with HTML automatically escaped.- Parameters:
caption- The message- Returns:
- The Notification
- See Also:
Notification(String),show(Page)
-
show
public static Notification show(String caption, Notification.Type type)
Shows a notification message the current page. The position and behavior of the message depends on the type, which is one of the basic types defined inNotification, for instanceNotification.Type.WARNING_MESSAGE. The caption is rendered as plain text with HTML automatically escaped.- Parameters:
caption- The messagetype- The message type- Returns:
- The Notification
- See Also:
Notification(String, Type),show(Page)
-
show
public static Notification show(String caption, String description, Notification.Type type)
Shows a notification message the current page. The position and behavior of the message depends on the type, which is one of the basic types defined inNotification, for instance Notification.TYPE_WARNING_MESSAGE. The caption is rendered as plain text with HTML automatically escaped.- Parameters:
caption- The messagedescription- The message descriptiontype- The message type- Returns:
- The Notification
- See Also:
Notification(String, String, Type),show(Page)
-
addCloseListener
public Registration addCloseListener(Notification.CloseListener listener)
Adds a CloseListener to the Notification.- Parameters:
listener- the CloseListener to add, notnull- Since:
- 8.2
-
-