Class MessageList

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.messages.MessageList
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, LocaleChangeObserver, Serializable

@Tag("vaadin-message-list") @JsModule("./messageListConnector.js") @JsModule("@vaadin/message-list/src/vaadin-message-list.js") @NpmPackage(value="@vaadin/message-list", version="25.2.0-alpha13") public class MessageList extends Component implements HasStyle, HasSize, LocaleChangeObserver
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).
Author:
Vaadin Ltd.
See Also:
  • 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(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.1
      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
    • 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 Signal<MessageListItem>> SignalBinding<List<S>> bindItems(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.1
    • localeChange

      public void localeChange(LocaleChangeEvent event)
      Description copied from interface: LocaleChangeObserver
      Notifies when the UI locale is changed.
      Specified by:
      localeChange in interface LocaleChangeObserver
      Parameters:
      event - locale change event with event details
    • 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.
    • isMarkdown

      public boolean isMarkdown()
      Returns whether the messages are parsed as markdown.
      Returns:
      true if the message text is parsed as Markdown.
    • 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.
    • isAnnounceMessages

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

      public Registration addAttachmentClickListener(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