Class ClipboardBinding
java.lang.Object
com.vaadin.flow.component.clipboard.ClipboardBinding
- All Implemented Interfaces:
Serializable
Fluent surface returned from
Clipboard.onClick(T). Each write*
action attaches one WriteToClipboardAction to the underlying
Trigger.
Actions come in two flavours: fire-and-forget (one argument) and observed
(with onCopied/onError callbacks). onCopied receives
the string that was copied; onError receives the browser's error.
Both consumers are required in the observed form — pass s -> {} or
err -> {} to opt out of one.
Button copy = new Button("Copy");
Clipboard.onClick(copy).writeText(textField);
Clipboard.onClick(copy).writeText(textField,
copied -> Notification.show("Copied " + copied),
err -> Notification.show("Failed: " + err.message()));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidwrite(ClipboardContent content) Copies a multi-format payload to the clipboard, packed into a singleClipboardItem.voidwrite(ClipboardContent content, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) Likewrite(ClipboardContent)but reports the outcome back to the server.voidCopies a literal HTML string to the clipboard astext/htmlwhen the underlying trigger fires.voidwriteHtml(String literal, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteHtml(String)but reports the outcome back to the server.writeText(C source) Copies the currentvalueproperty of the given component (typically an input field) to the clipboard astext/plainwhen the underlying trigger fires.writeText(C source, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteText(Component)but reports the outcome back to the server.voidCopies a literal string to the clipboard astext/plainwhen the underlying trigger fires.voidwriteText(String literal, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteText(String)but reports the outcome of the write promise back to the server.
-
Method Details
-
writeText
Copies a literal string to the clipboard astext/plainwhen the underlying trigger fires.- Parameters:
literal- the value to copy, notnull
-
writeText
public void writeText(String literal, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteText(String)but reports the outcome of the write promise back to the server.- Parameters:
literal- the value, notnullonCopied- UI-thread callback receiving the copied string, notnullonError- UI-thread callback receiving the browser's error, notnull
-
writeText
Copies the currentvalueproperty of the given component (typically an input field) to the clipboard astext/plainwhen the underlying trigger fires. The value is read on the client at the moment the trigger fires, so subsequent edits are reflected without any server round-trip.- Type Parameters:
C- component type implementingHasValue<?, String>- Parameters:
source- the component whosevalueshould be copied, notnull
-
writeText
public <C extends Component & HasValue<?,String>> void writeText(C source, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteText(Component)but reports the outcome back to the server.- Type Parameters:
C- component type implementingHasValue<?, String>- Parameters:
source- the component whosevalueshould be copied, notnullonCopied- UI-thread callback receiving the copied string, notnullonError- UI-thread callback receiving the browser's error, notnull
-
writeHtml
Copies a literal HTML string to the clipboard astext/htmlwhen the underlying trigger fires.- Parameters:
literal- the HTML, notnull
-
writeHtml
public void writeHtml(String literal, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) LikewriteHtml(String)but reports the outcome back to the server.- Parameters:
literal- the HTML, notnullonCopied- UI-thread callback receiving the copied HTML, notnullonError- UI-thread callback receiving the browser's error, notnull
-
write
Copies a multi-format payload to the clipboard, packed into a singleClipboardItem.- Parameters:
content- the content, notnull; must have at least one slot set- Throws:
IllegalArgumentException- ifcontenthas no slots set
-
write
public void write(ClipboardContent content, SerializableConsumer<@Nullable String> onCopied, SerializableConsumer<PromiseAction.Error> onError) Likewrite(ClipboardContent)but reports the outcome back to the server.- Parameters:
content- the content, notnull; must have at least one slot setonCopied- UI-thread callback receiving thetext/plainvalue if present, otherwise thetext/htmlvalue, notnullonError- UI-thread callback receiving the browser's error, notnull
-