Documentation

Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Store Ordered Values in Topics

The Topic API provides the CollaborationList data structure to store ordered values and subscribe to their changes.

You can get a CollaborationList by its name in the Topic connection activation callback.

Source code
CollaborationListExample.java

When you have gotten the list instance, you can insert values at the end of the list with the insertLast() method.

Source code
CollaborationListExample.java

Since the insertion is asynchronous, the method returns a result object from which you can get a CompletableFuture that you can use to determine when the insertion has been done.

Source code
CollaborationListExample.java

The result object also provides the ListKey of the inserted item, which you can use to replace the item itself, get its current value or remove it from the list.

Source code
CollaborationListExample.java

Advanced List Operations

The ListOperation class allows you to prepare a list operation that can then be applied to the list using the CollaborationList::apply method.

The reason you may want to use this class is to define certain conditions that must be met when the operation is attempted. If a condition isn’t met, the operation isn’t be completed. This is useful to protect against duplicate operations.

Static methods of ListOperation
  • insertFirst() Value is inserted at the beginning of the list.

  • insertLast() Value is inserted at the end of the list.

  • insertBefore() Value is inserted immediately before a specified key.

  • insertAfter() Value is inserted immediately after a specified key.

  • insertBetween() Shorthand for insertAfter(value, keyBefore).ifNext(keyBefore, keyAfter).

Conditional methods of ListOperation
  • ifFirst(key) The specified key must be the first in the list.

  • ifLast(key) The specified key must be the last in the list.

  • ifPrev(key, keyPrev) The specified keyPrev must be immediately before key.

  • ifNext(key, keyNext) The specified keyNext must be immediately after key.

  • ifEmpty() The list must have no entries.

  • ifNotEmpty() The list must have at least one entry.

Source code
CollaborationListExample.java

106C5E39-A7E3-48D9-AF74-2E9A9A6576DF`