Vaadin Platform (vaadin-core) - Core component of the Vaadin web framework platform
Collaboration, messages, login components, and frontend integration.
Quick links: Collaboration Engine | Messages | Event Handling | Functional Interfaces
Real-time collaboration capabilities for multi-user applications with presence awareness.
/**
* Main entry point for collaboration features
* Provides real-time synchronization across multiple users
*/
class CollaborationEngine {
/**
* Gets the collaboration engine instance
* @return CollaborationEngine instance
*/
static CollaborationEngine getInstance();
/**
* Configures the collaboration engine
* @param service - Vaadin service
* @param configuration - Engine configuration
*/
static void configure(VaadinService service, CollaborationEngineConfiguration configuration);
/**
* Gets user info from request
* @param request - Vaadin request
* @return UserInfo instance
*/
UserInfo getUserInfo(VaadinRequest request);
/**
* Creates a collaborative binder
* @param session - Vaadin session
* @param beanType - Bean class type
* @return CollaborationBinder instance
*/
CollaborationBinder createBinder(VaadinSession session, Class<?> beanType);
}
/**
* Configuration for collaboration engine
*/
class CollaborationEngineConfiguration {
/**
* Sets whether to automatically activate push
* @param automaticallyActivatePush - true to auto-activate
*/
void setAutomaticallyActivatePush(boolean automaticallyActivatePush);
/**
* Sets the license key for production use
* @param licenseKey - License key string
*/
void setLicenseKey(String licenseKey);
}
/**
* User information for collaboration
*/
class UserInfo {
UserInfo(String userId);
UserInfo(String userId, String name);
UserInfo(String userId, String name, String image);
String getId();
String getName();
String getImage();
String getAbbreviation();
String getColorIndex();
}
/**
* Avatar group showing active collaborators
*/
class CollaborationAvatarGroup extends Component {
/**
* Creates collaborative avatar group
* @param localUser - Local user info
* @param topicId - Topic identifier
*/
CollaborationAvatarGroup(UserInfo localUser, String topicId);
/**
* Creates with engine instance
* @param localUser - Local user info
* @param engine - Collaboration engine
* @param topicId - Topic identifier
*/
CollaborationAvatarGroup(UserInfo localUser, CollaborationEngine engine, String topicId);
/**
* Sets maximum avatars visible
* @param maxItemsVisible - Maximum count
*/
void setMaxItemsVisible(int maxItemsVisible);
/**
* Sets whether to show own user
* @param ownUser - true to show own user
*/
void setOwnUser(boolean ownUser);
}
/**
* Collaborative form binder with real-time synchronization
*/
class CollaborationBinder extends Binder {
/**
* Creates collaborative binder
* @param beanType - Bean class type
* @param localUser - Local user info
* @param topicId - Topic identifier
*/
CollaborationBinder(Class<?> beanType, UserInfo localUser, String topicId);
/**
* Sets the collaboration topic
* @param topicId - Topic identifier
* @param defaultValue - Supplier for default value
*/
void setTopic(String topicId, Supplier<?> defaultValue);
/**
* Adds value change listener for collaborative updates
* @param listener - Value change listener
* @return Registration for removing listener
*/
Registration addValueChangeListener(ValueChangeListener listener);
}
/**
* Collaborative list with real-time synchronization
*/
class CollaborationList<T> {
/**
* Creates collaborative list
* @param engine - Collaboration engine
* @param localUser - Local user info
* @param topicId - Topic identifier
* @param itemType - Item class type
*/
CollaborationList(CollaborationEngine engine, UserInfo localUser, String topicId, Class<T> itemType);
/**
* Inserts item at index
* @param index - Insert position
* @param item - Item to insert
*/
void insertItem(int index, T item);
/**
* Appends item to end
* @param item - Item to append
*/
void appendItem(T item);
/**
* Removes item at index
* @param index - Item index
*/
void removeItem(int index);
/**
* Updates item at index
* @param index - Item index
* @param item - Updated item
*/
void setItem(int index, T item);
/**
* Gets item at index
* @param index - Item index
* @return Item at index
*/
T getItem(int index);
/**
* Gets list size
* @return Size of list
*/
int getSize();
/**
* Subscribes to collaborative changes
* @param subscriber - Change subscriber
* @return Registration for removing subscription
*/
Registration subscribe(CollaborationListSubscriber<T> subscriber);
}
/**
* Subscriber for collaborative list changes
*/
interface CollaborationListSubscriber<T> {
/**
* Called when item is inserted
* @param index - Insert position
* @param item - Inserted item
* @param user - User who inserted
*/
void onItemInserted(int index, T item, UserInfo user);
/**
* Called when item is updated
* @param index - Item index
* @param item - Updated item
* @param user - User who updated
*/
void onItemUpdated(int index, T item, UserInfo user);
/**
* Called when item is removed
* @param index - Item index
* @param item - Removed item
* @param user - User who removed
*/
void onItemRemoved(int index, T item, UserInfo user);
}
/**
* Collaborative message list for real-time chat
*/
class CollaborationMessageList {
/**
* Creates collaborative message list
* @param localUser - Local user info
* @param topicId - Topic identifier
* @param messageList - MessageList component
* @param messageInput - MessageInput component
*/
CollaborationMessageList(UserInfo localUser, String topicId,
MessageList messageList, MessageInput messageInput);
/**
* Sets custom submit handler
* @param submitter - Submit handler
*/
void setSubmitter(BiConsumer<MessageInput, MessageListItem> submitter);
}License Note: CollaborationEngine is free for development (up to 10 users) but requires a separate license for production use.
Usage Examples:
// Collaborative avatar group
UserInfo localUser = new UserInfo("user-123", "John Doe", "/images/john.png");
CollaborationAvatarGroup avatarGroup = new CollaborationAvatarGroup(
localUser, "document-456"
);
avatarGroup.setMaxItemsVisible(5);
add(avatarGroup);
// Collaborative form
UserInfo localUser = new UserInfo("user-123", "John Doe");
CollaborationBinder<Person> binder = new CollaborationBinder<>(
Person.class, localUser, "person-789"
);
TextField nameField = new TextField("Name");
TextField emailField = new TextField("Email");
binder.forField(nameField).bind(Person::getName, Person::setName);
binder.forField(emailField).bind(Person::getEmail, Person::setEmail);
binder.setTopic("person-789", Person::new);
// Collaborative list
UserInfo localUser = new UserInfo("user-123", "John Doe");
CollaborationList<Task> taskList = new CollaborationList<>(
CollaborationEngine.getInstance(),
localUser, "tasks-project-456", Task.class
);
// Add item
taskList.appendItem(new Task("Review documentation"));
// Subscribe to changes
taskList.subscribe(new CollaborationListSubscriber<Task>() {
@Override
public void onItemInserted(int index, Task item, UserInfo user) {
Notification.show(user.getName() + " added: " + item.getTitle());
}
@Override
public void onItemUpdated(int index, Task item, UserInfo user) {
Notification.show(user.getName() + " updated: " + item.getTitle());
}
@Override
public void onItemRemoved(int index, Task item, UserInfo user) {
Notification.show(user.getName() + " removed: " + item.getTitle());
}
});
// Collaborative message list
UserInfo localUser = new UserInfo("user-123", "John Doe");
MessageList messageList = new MessageList();
MessageInput messageInput = new MessageInput();
CollaborationMessageList collaborationMessageList = new CollaborationMessageList(
localUser, "chat-topic-123", messageList, messageInput
);
// Optional: custom submit handler
collaborationMessageList.setSubmitter((input, item) -> {
// Custom submission logic
item.setText(input.getValue());
item.setTime(Instant.now());
item.setUserName(localUser.getName());
});
add(messageList, messageInput);Chat and messaging components.
class MessageList extends Component {
MessageList();
void setItems(List<MessageListItem> items);
}
class MessageListItem implements Serializable {
MessageListItem();
MessageListItem(String text);
MessageListItem(String text, Instant time, String userName);
void setText(String text);
void setTime(Instant time);
void setUserName(String userName);
void setUserImage(String userImage);
void setUserColorIndex(Integer colorIndex);
void setUserAbbreviation(String abbreviation);
}
class MessageInput extends Component {
MessageInput();
void setPlaceholder(String placeholder);
void setI18n(MessageInputI18n i18n);
Registration addSubmitListener(ComponentEventListener<SubmitEvent> listener);
}
class SubmitEvent extends ComponentEvent<MessageInput> {
String getValue();
}
class MessageInputI18n implements Serializable {
void setSend(String send);
void setMessage(String message);
}Example:
@Route("chat")
public class ChatView extends VerticalLayout {
private MessageList messageList;
private MessageInput messageInput;
private List<MessageListItem> messages = new ArrayList<>();
public ChatView() {
messageList = new MessageList();
messageList.setHeight("500px");
messageInput = new MessageInput();
messageInput.addSubmitListener(e -> addMessage(e.getValue()));
add(messageList, messageInput);
setSizeFull();
}
private void addMessage(String text) {
MessageListItem msg = new MessageListItem(
text, Instant.now(), "Current User"
);
msg.setUserAbbreviation("CU");
msg.setUserColorIndex(2);
messages.add(msg);
messageList.setItems(messages);
messageInput.setValue("");
}
}enum ValueChangeMode {
EAGER, // On every keystroke
LAZY, // On blur
TIMEOUT, // After timeout
ON_BLUR, // On blur
ON_CHANGE // On change
}Example:
TextField searchField = new TextField("Search");
searchField.setValueChangeMode(ValueChangeMode.LAZY);
searchField.setValueChangeTimeout(500);
searchField.addValueChangeListener(e -> performSearch(e.getValue()));interface ComponentEventListener<E extends ComponentEvent<?>> extends Serializable {
void onComponentEvent(E event);
}
class ClickEvent<T extends Component> extends ComponentEvent<T> {
int getClientX();
int getClientY();
boolean isAltKey();
boolean isCtrlKey();
boolean isShiftKey();
}
class ComponentValueChangeEvent<C extends Component, V>
extends ComponentEvent<C> implements HasValue.ValueChangeEvent<V> {
V getOldValue();
V getValue();
boolean isFromClient();
}
interface Registration extends Serializable {
void remove();
}Examples:
Button button = new Button("Save", e -> {
if (e.isCtrlKey()) {
saveAsDraft();
} else {
save();
}
});
TextField field = new TextField("Name");
field.addValueChangeListener(e -> {
String oldValue = e.getOldValue();
String newValue = e.getValue();
if (!newValue.equals(oldValue)) {
validate(newValue);
}
});@FunctionalInterface
interface ValueProvider<SOURCE, TARGET> extends SerializableFunction<SOURCE, TARGET> {
TARGET apply(SOURCE source);
}
@FunctionalInterface
interface Setter<BEAN, VALUE> extends BiConsumer<BEAN, VALUE>, Serializable {
void accept(BEAN bean, VALUE value);
}
@FunctionalInterface
interface ItemLabelGenerator<T> extends SerializableFunction<T, String> {
String apply(T item);
}
@FunctionalInterface
interface SerializableFunction<T, R> extends Function<T, R>, Serializable {
R apply(T t);
}
@FunctionalInterface
interface SerializableConsumer<T> extends Consumer<T>, Serializable {
void accept(T t);
}
@FunctionalInterface
interface SerializablePredicate<T> extends Predicate<T>, Serializable {
boolean test(T t);
}Install with Tessl CLI
npx tessl i tessl/maven-com-vaadin--vaadin-core@24.9.1