Package org.vaadin.addons.skeleton
Class Skeleton
java.lang.Object
org.vaadin.addons.skeleton.Skeleton
Shows skeleton placeholders over every child of a component while its data loads.
// Simplest: show, then hide yourself
Skeleton.show(profileCard);
...
Skeleton.hide(profileCard);
// Recommended: load in the background, fill the UI, hide automatically
Skeleton.load(profileCard,
() -> userService.fetchProfile(id), // runs off the UI thread
profile -> { // runs with the UI locked
name.setText(profile.name());
title.setText(profile.title());
});
All methods except the loading task itself must be called while holding the UI
lock (i.e. from a listener, a view constructor or ui.access).
load(com.vaadin.flow.component.Component, java.util.function.Supplier<T>, com.vaadin.flow.function.SerializableConsumer<T>) requires server push (@Push on the app shell). Without push the
browser is not told when the background task finishes, so the skeleton stays visible
until the next unrelated server round trip.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidexclude(com.vaadin.flow.component.Component component) Leaves this component (and everything inside it) visible and uncovered.static voidhide(com.vaadin.flow.component.Component container) Removes the placeholders and reveals the real content.static booleanisShowing(com.vaadin.flow.component.Component container) static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess) Shows the skeleton, runstaskin the background, then hands the result toonSuccesswith the UI locked and hides the skeleton.static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError) Likeload(Component, Supplier, SerializableConsumer)with an error callback.static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, SkeletonOptions options, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError, Executor executor) Full version ofload.static voidmarkAsLeaf(com.vaadin.flow.component.Component component) Treats this component as a single placeholder block instead of descending into its children (useful for custom composite components).static voidsetDefaultExecutor(Executor executor) Sets the executor used byload(com.vaadin.flow.component.Component, java.util.function.Supplier<T>, com.vaadin.flow.function.SerializableConsumer<T>)when none is given, e.g. a Spring task executor.static voidshow(com.vaadin.flow.component.Component container) Shows placeholders over all leaf components insidecontainer.static voidshow(com.vaadin.flow.component.Component container, SkeletonOptions options) Shows placeholders overcontainerusing the given options.
-
Method Details
-
show
public static void show(com.vaadin.flow.component.Component container) Shows placeholders over all leaf components insidecontainer. -
show
Shows placeholders overcontainerusing the given options. -
hide
public static void hide(com.vaadin.flow.component.Component container) Removes the placeholders and reveals the real content. Safe to call twice. -
isShowing
public static boolean isShowing(com.vaadin.flow.component.Component container) -
markAsLeaf
public static void markAsLeaf(com.vaadin.flow.component.Component component) Treats this component as a single placeholder block instead of descending into its children (useful for custom composite components). -
exclude
public static void exclude(com.vaadin.flow.component.Component component) Leaves this component (and everything inside it) visible and uncovered. -
setDefaultExecutor
Sets the executor used byload(com.vaadin.flow.component.Component, java.util.function.Supplier<T>, com.vaadin.flow.function.SerializableConsumer<T>)when none is given, e.g. a Spring task executor. -
load
public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess) Shows the skeleton, runstaskin the background, then hands the result toonSuccesswith the UI locked and hides the skeleton. Requires@Push. -
load
public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError) Likeload(Component, Supplier, SerializableConsumer)with an error callback. -
load
public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, SkeletonOptions options, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError, Executor executor) Full version ofload.- Parameters:
onError- called with the UI locked iftaskthrows; may benull, in which case the error is logged. The skeleton is hidden either way.executor- wheretaskruns
-