Class MessageList

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.messages.MessageList
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasThemeVariant<MessageListVariant>, com.vaadin.flow.i18n.LocaleChangeObserver, Serializable

@Tag("vaadin-message-list") @JsModule("./messageListConnector.js") @JsModule("@vaadin/message-list/src/vaadin-message-list.js") @NpmPackage(value="@vaadin/message-list", version="https://pkg.pr.new/vaadin/web-components/@vaadin/message-list@3141b6e97ee28811344a2e851112c4ba1ae340ce") public class MessageList extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasSize, com.vaadin.flow.i18n.LocaleChangeObserver, com.vaadin.flow.component.shared.HasThemeVariant<MessageListVariant>
Message List allows you to show a list of messages, for example, a chat log. You can configure the text content, information about the sender and the time of sending for each message. The component displays a list of messages that can be configured with setItems(Collection).
Since:
14.7
Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Event fired when an attachment is clicked in the message list.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new message list component.
    Creates a new message list component, with the provided items rendered as messages.
    MessageList(com.vaadin.flow.signals.Signal<List<S>> itemsSignal)
    Creates a new message list component with the provided signal bound to the items.
    Creates a new message list component, with the provided items rendered as messages.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.shared.Registration
    addAttachmentClickListener(com.vaadin.flow.component.ComponentEventListener<MessageList.AttachmentClickEvent> listener)
    Adds a listener that is called when an attachment is clicked.
    void
    Adds a single item to be rendered as a message at the end of this message list.
    <S extends com.vaadin.flow.signals.Signal<MessageListItem>>
    com.vaadin.flow.dom.SignalBinding<List<S>>
    bindItems(com.vaadin.flow.signals.Signal<List<S>> itemsSignal)
    Binds the given signal to the items of the message list as a one-way binding so that the rendered messages are updated when the signal's value or any individual item signal changes.
    <S extends com.vaadin.flow.signals.Signal<MessageListUser>>
    com.vaadin.flow.dom.SignalBinding<List<MessageListUser>>
    bindTypingUsers(com.vaadin.flow.signals.Signal<List<S>> typingUsersSignal)
    Binds the given signal to the users that are currently typing as a one-way binding so that the typing indicator is updated when the signal's value or any individual user signal changes.
    Gets the internationalization object previously set for this component.
    Gets the items that are rendered as message components in this message list.
    Gets the style in which the typing indicator is rendered.
    Gets the users that are currently typing.
    boolean
    Returns whether new messages are announced to assistive technologies.
    boolean
    Returns whether the messages are parsed as markdown.
    void
    localeChange(com.vaadin.flow.i18n.LocaleChangeEvent event)
     
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    setAnnounceMessages(boolean announceMessages)
    When set to true, new messages are announced to assistive technologies using ARIA live regions.
    void
    Sets the internationalization object for this component.
    void
    Sets the items that will be rendered as messages in this message list.
    void
    Sets the items that will be rendered as messages in this message list.
    void
    setMarkdown(boolean markdown)
    Sets whether the messages should be parsed as markdown.
    void
    Sets the style in which the typing indicator is rendered.
    void
    Sets the users that are currently typing.
    void
    Sets the users that are currently typing.

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttached

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasSize

    bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
  • Constructor Details

    • MessageList

      public MessageList()
      Creates a new message list component. To populate the content of the list, use setItems(Collection).
    • MessageList

      public MessageList(Collection<MessageListItem> items)
      Creates a new message list component, with the provided items rendered as messages.
      Parameters:
      items - the items to render as messages
      See Also:
    • MessageList

      public MessageList(MessageListItem... items)
      Creates a new message list component, with the provided items rendered as messages.
      Parameters:
      items - the items to render as messages
      See Also:
    • MessageList

      public MessageList(com.vaadin.flow.signals.Signal<List<S>> itemsSignal)
      Creates a new message list component with the provided signal bound to the items.

      The rendered messages are updated when the signal's value or any individual item signal changes. Any signal change results in a full update.

      Type Parameters:
      S - the type of signal holding individual items
      Parameters:
      itemsSignal - the signal to bind the items to, not null
      Since:
      25.2
      See Also:
  • Method Details

    • setItems

      public void setItems(Collection<MessageListItem> items)
      Sets the items that will be rendered as messages in this message list.
      Parameters:
      items - the items to set, not null and not containing any null items
    • setItems

      public void setItems(MessageListItem... items)
      Sets the items that will be rendered as messages in this message list.
      Parameters:
      items - the items to set, none of which can be null
    • addItem

      public void addItem(MessageListItem item)
      Adds a single item to be rendered as a message at the end of this message list.
      Parameters:
      item - the item to add, not null
      Since:
      24.8
    • getItems

      public List<MessageListItem> getItems()
      Gets the items that are rendered as message components in this message list.
      Returns:
      an unmodifiable view of the list of items
    • bindItems

      public <S extends com.vaadin.flow.signals.Signal<MessageListItem>> com.vaadin.flow.dom.SignalBinding<List<S>> bindItems(com.vaadin.flow.signals.Signal<List<S>> itemsSignal)
      Binds the given signal to the items of the message list as a one-way binding so that the rendered messages are updated when the signal's value or any individual item signal changes. Any signal change results in a full update.

      When a signal is bound, the items are kept synchronized with the signal value while the component is attached. When the component is detached, signal value changes have no effect.

      While a signal is bound, any attempt to modify items manually through setItems(Collection) or addItem(MessageListItem) throws a BindingActiveException.

      Type Parameters:
      S - the type of signal holding individual items
      Parameters:
      itemsSignal - the signal to bind the items to, not null
      Since:
      25.2
    • localeChange

      public void localeChange(com.vaadin.flow.i18n.LocaleChangeEvent event)
      Specified by:
      localeChange in interface com.vaadin.flow.i18n.LocaleChangeObserver
    • setMarkdown

      public void setMarkdown(boolean markdown)
      Sets whether the messages should be parsed as markdown. By default, this is set to false.
      Parameters:
      markdown - true if the message text is parsed as Markdown.
      Since:
      24.8
    • isMarkdown

      public boolean isMarkdown()
      Returns whether the messages are parsed as markdown.
      Returns:
      true if the message text is parsed as Markdown.
      Since:
      24.8
    • setAnnounceMessages

      public void setAnnounceMessages(boolean announceMessages)
      When set to true, new messages are announced to assistive technologies using ARIA live regions. By default, this is set to false.
      Parameters:
      announceMessages - true if new messages should be announced to assistive technologies.
      Since:
      24.8
    • isAnnounceMessages

      public boolean isAnnounceMessages()
      Returns whether new messages are announced to assistive technologies.
      Returns:
      true if new messages are announced to assistive technologies.
      Since:
      24.8
    • getTypingUsers

      public List<MessageListUser> getTypingUsers()
      Gets the users that are currently typing.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Returns:
      an unmodifiable view of the users that are currently typing, empty by default
      Since:
      25.3
    • setTypingUsers

      public void setTypingUsers(List<MessageListUser> typingUsers)
      Sets the users that are currently typing. A typing indicator with the names and avatars of these users is rendered at the end of the message list. Pass an empty list to hide the typing indicator.

      The message list does not remove the users on its own. It is up to the application to clear them once the users have stopped typing.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Parameters:
      typingUsers - the users that are currently typing, not null and not containing any null users
      Since:
      25.3
    • setTypingUsers

      public void setTypingUsers(MessageListUser... typingUsers)
      Sets the users that are currently typing. A typing indicator with the names and avatars of these users is rendered at the end of the message list. Pass no users to hide the typing indicator.

      The message list does not remove the users on its own. It is up to the application to clear them once the users have stopped typing.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Parameters:
      typingUsers - the users that are currently typing, none of which can be null
      Since:
      25.3
    • bindTypingUsers

      public <S extends com.vaadin.flow.signals.Signal<MessageListUser>> com.vaadin.flow.dom.SignalBinding<List<MessageListUser>> bindTypingUsers(com.vaadin.flow.signals.Signal<List<S>> typingUsersSignal)
      Binds the given signal to the users that are currently typing as a one-way binding so that the typing indicator is updated when the signal's value or any individual user signal changes.

      When a signal is bound, the typing users are kept synchronized with the signal value while the component is attached. When the component is detached, signal value changes have no effect.

      While a signal is bound, any attempt to modify the typing users manually through setTypingUsers(List) throws a BindingActiveException.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Type Parameters:
      S - the type of signal holding individual users
      Parameters:
      typingUsersSignal - the signal to bind the typing users to, not null
      Returns:
      a SignalBinding that can be used to register onChange callbacks
      Since:
      25.3
    • getTypingIndicatorType

      public MessageListTypingIndicatorType getTypingIndicatorType()
      Gets the style in which the typing indicator is rendered.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Returns:
      the typing indicator type, MessageListTypingIndicatorType.DEFAULT by default
      Since:
      25.3
    • setTypingIndicatorType

      public void setTypingIndicatorType(MessageListTypingIndicatorType typingIndicatorType)
      Sets the style in which the typing indicator is rendered. The style is applied right away, also when the typing indicator is currently displayed. By default, the typing indicator is rendered in the MessageListTypingIndicatorType.DEFAULT style.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Parameters:
      typingIndicatorType - the typing indicator type, not null
      Since:
      25.3
    • getI18n

      public MessageListI18n getI18n()
      Gets the internationalization object previously set for this component.

      Note: updating the object properties after getting the i18n object does not update the component. Set the object again with setI18n(MessageListI18n) to apply the changes.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Returns:
      the i18n object, or null if no i18n object has been set
      Since:
      25.3
    • setI18n

      public void setI18n(MessageListI18n i18n)
      Sets the internationalization object for this component. The texts are applied right away, also when the typing indicator is currently displayed.

      Note: updating the object properties after setting the i18n object does not update the component. Set the object again to apply the changes.

      This API is experimental and needs to be enabled with the com.vaadin.experimental.messageListTypingIndicator or com.vaadin.experimental.aiComponents feature flag.

      Parameters:
      i18n - the i18n object, not null
      Since:
      25.3
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • addAttachmentClickListener

      public com.vaadin.flow.shared.Registration addAttachmentClickListener(com.vaadin.flow.component.ComponentEventListener<MessageList.AttachmentClickEvent> listener)
      Adds a listener that is called when an attachment is clicked.
      Parameters:
      listener - the listener to add
      Returns:
      a registration that can be used to remove the listener
      Since:
      25.1