Class CookieConsent
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.cookieconsent.CookieConsent
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasStyle,Serializable
@Tag("vaadin-cookie-consent")
@NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.12") @NpmPackage(value="@vaadin/cookie-consent",version="24.7.12")
@JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/cookie-consent/src/vaadin-cookie-consent.js") @JsModule("./cookieConsentConnector.js")
public class CookieConsent
extends Component
implements HasStyle
Cookie Consent is a component for showing a cookie consent banner the first
time a user visits the application, until the banner is dismissed.
By default, the banner is shown at the top of the screen with a predefined text, a link to cookiesandyou.com which explains what cookies are, and a consent button.
Cookie Consent is fully customizable. You can customize the message, the "Learn More" link, the "Dismiss" button, as well as the component’s position.
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates a banner with default values.CookieConsent(String message, String dismissLabel, String learnMoreLabel, String learnMoreLink, CookieConsent.Position position) Creates a banner with the specified data -
Method Summary
Modifier and TypeMethodDescriptiongetStyle()Gets the style instance for managing inline styles for the element of this component.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidsetCookieName(String cookieName) Sets the name of the cookie to remember that the user has consented.voidsetDismissLabel(String dismissLabel) Sets the dismiss/consent button's textvoidsetLearnMoreLabel(String learnMoreLabel) Sets the label of the 'learn more' linkvoidsetLearnMoreLink(String learnMoreLink) Sets the URL of the 'learn more' linkvoidsetMessage(String message) Sets the consent message to show in the banner.voidsetPosition(CookieConsent.Position position) Sets the position of the banner on the page.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
CookieConsent
public CookieConsent()Creates a banner with default values. -
CookieConsent
public CookieConsent(String message, String dismissLabel, String learnMoreLabel, String learnMoreLink, CookieConsent.Position position) Creates a banner with the specified data- Parameters:
message- The message to show in the banner.dismissLabel- The text to show on the dismiss/consent button.learnMoreLabel- The text to show on the 'learn more' link.learnMoreLink- The URL the 'learn more' link should open.position- Determines the position of the banner.
-
-
Method Details
-
setMessage
Sets the consent message to show in the banner.- Parameters:
message- The message to show in the banner.
-
setDismissLabel
Sets the dismiss/consent button's text- Parameters:
dismissLabel- The text of the button.
-
setLearnMoreLabel
Sets the label of the 'learn more' link- Parameters:
learnMoreLabel- The text to show on the 'learn more' link.
-
setLearnMoreLink
Sets the URL of the 'learn more' link- Parameters:
learnMoreLink- The URL the 'learn more' link should open.
-
setPosition
Sets the position of the banner on the page.- Parameters:
position- Determines the position of the banner.- Throws:
NullPointerException- if position is null.
-
setCookieName
Sets the name of the cookie to remember that the user has consented. This rarely needs to be changed.- Parameters:
cookieName- The name of the cookie.
-
getStyle
Description copied from interface:HasStyleGets the style instance for managing inline styles for the element of this component.- Specified by:
getStylein interfaceHasStyle- Returns:
- the style object for the element, not
null - Throws:
UnsupportedOperationException- CookieConsent does not support adding styles
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method.
-