Class ConfirmDialog
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasComponents,HasElement,HasEnabled,HasOrderedComponents,HasSize,HasStyle,Serializable
Confirm Dialog consists of:
- Title
- Message
- Footer
- “Cancel” button
- “Reject” button
- “Confirm” button
Each Confirm Dialog should have a title and/or message. The “Confirm” button is shown by default, while the two other buttons are not (they must be explicitly enabled to be displayed).
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class`cancel` is sent when the user clicks Cancel button or presses Escape key.static class`confirm` is sent when the user clicks Confirm buttonstatic class`reject` is sent when the user clicks Reject button -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty dialog with a Confirm buttonConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener) Creates a dialog with a Confirm button with its click listener and a given textsConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String cancelText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Creates a two button dialog with Confirm and Cancel buttonsConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String rejectText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener, String cancelText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Creates a three button dialog with Confirm, Reject and Cancel buttons -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.since v24.4, not supportedvoidDeprecated.since v24.4, not supportedvoidadd(Collection<Component> components) Deprecated.since v24.4, not supportedAdds `cancel` event listenervoidaddComponentAsFirst(Component component) Deprecated.since v24.4, not supportedvoidaddComponentAtIndex(int index, Component component) Deprecated.since v24.4, not supportedAdds `confirm` event listenerAdds `reject` event listenervoidclose()Closes the dialog.Gets the `aria-describedby` attribute of the dialog overlay.Gets the set of CSS class names used for this element.getComponentAt(int index) Deprecated.since v24.4, not supportedintDeprecated.since v24.4, not supportedGets the height defined for the component.getStyle()Gets the style instance for managing inline styles for the element of this component.getWidth()Gets the width defined for the component.intDeprecated.since v24.4, not supportedbooleanGets whether this dialog can be closed by hitting the esc-key or not.booleanisOpened()protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidopen()Opens the dialog.voidDeprecated.since v24.4, not supportedvoidremove(Collection<Component> components) Deprecated.since v24.4, not supportedvoidDeprecated.since v24.4, not supportedvoidDeprecated.since v24.4, not supportedvoidsetAriaDescribedBy(String describedBy) Sets the `aria-describedby` attribute of the dialog overlay.voidsetCancelable(boolean cancelable) Whether to show or hide Cancel button.voidsetCancelButton(Component component) Sets custom cancel buttonvoidsetCancelButton(Element element) Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedvoidsetCancelButton(String buttonText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Sets Cancel button text and `cancel` event listener.voidsetCancelButton(String buttonText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener, String theme) Sets Cancel button text, `cancel` event listener and Cancel button theme.voidsetCancelButtonTheme(String cancelTheme) Sets Cancel button themevoidsetCancelText(String cancelText) Sets Cancel button textvoidsetClassName(String className) Sets the CSS class names of the dialog overlay element.voidsetCloseOnEsc(boolean closeOnEsc) Sets whether this dialog can be closed by hitting the esc-key or not.voidsetConfirmButton(Component component) Sets custom confirm buttonvoidsetConfirmButton(Element element) Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedvoidsetConfirmButton(String buttonText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener) Sets Confirm button text and `confirm` event listenervoidsetConfirmButton(String buttonText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String theme) Sets Confirm button text, `confirm` event listener and Confirm button themevoidsetConfirmButtonTheme(String confirmTheme) Sets Confirm button themevoidsetConfirmText(String confirmText) Sets Confirm button textvoidSets confirmation dialog custom headervoidDeprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedvoidSets confirmation dialog header textvoidSets the height of the component content area.voidsetOpened(boolean opened) Opens or closes the dialog.voidsetRejectable(boolean rejectable) Whether to show or hide Reject button.voidsetRejectButton(Component component) Sets custom Reject buttonvoidsetRejectButton(Element element) Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedvoidsetRejectButton(String buttonText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener) Sets Reject button text and `reject` event listener.voidsetRejectButton(String buttonText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener, String theme) Sets Reject button text, `reject` event listener, Reject button theme.voidsetRejectButtonTheme(String rejectTheme) Sets Reject button themevoidsetRejectText(String rejectText) Sets Reject button textvoidSets custom confirmation messagevoidDeprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedvoidSets confirmation message textvoidSets the width of the component content area.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.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasOrderedComponents
getChildrenMethods inherited from interface com.vaadin.flow.component.HasSize
getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, hasClassName, removeClassName, removeClassNames, setClassName
-
Constructor Details
-
ConfirmDialog
public ConfirmDialog()Creates an empty dialog with a Confirm button -
ConfirmDialog
public ConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener) Creates a dialog with a Confirm button with its click listener and a given texts- Parameters:
header- the header texttext- the confirmation message textconfirmText- the text inside Confirm buttonconfirmListener- the event listener for `confirm` event- See Also:
-
ConfirmDialog
public ConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String cancelText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Creates a two button dialog with Confirm and Cancel buttons- Parameters:
header- the header texttext- the confirmation message textconfirmText- the text inside Confirm buttonconfirmListener- the event listener for `confirm` eventcancelText- the text inside Cancel buttoncancelListener- the event listener for `cancel` event- See Also:
-
ConfirmDialog
public ConfirmDialog(String header, String text, String confirmText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String rejectText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener, String cancelText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Creates a three button dialog with Confirm, Reject and Cancel buttons- Parameters:
header- the header texttext- the confirmation message textconfirmText- the text inside Confirm buttonconfirmListener- the event listener for `confirm` eventrejectText- the text inside Reject buttonrejectListener- the event listener for `reject` eventcancelText- the text inside Cancel buttoncancelListener- the event listener for `cancel` event- See Also:
-
-
Method Details
-
getWidth
Description copied from interface:HasSizeGets the width defined for the component.Note that this does not return the actual size of the component but the width which has been set using
HasSize.setWidth(String). -
setWidth
Sets the width of the component content area.The width should be in a format understood by the browser, e.g. "100px" or "2.5em" (Using relative unit, such as percentage, will lead to unexpected results).
If the provided
widthvalue is null then width is removed. -
getHeight
Description copied from interface:HasSizeGets the height defined for the component.Note that this does not return the actual size of the component but the height which has been set using
HasSize.setHeight(String). -
setHeight
Sets the height of the component content area.The height should be in a format understood by the browser, e.g. "100px" or "2.5em" (Using relative unit, such as percentage, will lead to unexpected results).
If the provided
heightvalue is null then height is removed. -
setClassName
Sets the CSS class names of the dialog overlay element. This method overwrites any previous set class names.- Specified by:
setClassNamein interfaceHasStyle- Parameters:
className- a space-separated string of class names to set, ornullto remove all class names
-
getClassNames
Description copied from interface:HasStyleGets the set of CSS class names used for this element. The returned set can be modified to add or remove class names. The contents of the set is also reflected in the value of theclassattribute.Despite the name implying a list being returned, the return type is actually a
Setsince the in-browser return value behaves like aSetin Java.- Specified by:
getClassNamesin interfaceHasStyle- Returns:
- a list of class names, never
null - See Also:
-
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- ConfirmDialog does not support adding styles to overlay
-
setAriaDescribedBy
Sets the `aria-describedby` attribute of the dialog overlay.By default, all elements inside the message area are linked through the `aria-describedby` attribute. However, there are cases where this can confuse screen reader users (e.g. the dialog may present a password confirmation form). For these cases, it's better to associate only the elements that will help describe the confirmation dialog through this API.
To restore the generated value, pass `null` as argument
- Parameters:
describedBy- the attribute value
-
getAriaDescribedBy
Gets the `aria-describedby` attribute of the dialog overlay.Note that this will only return a value if
setAriaDescribedBy(String)was called before.- Returns:
- an optional aria-describedby of the dialog overlay, or an empty optional if no aria-describedby has been set
-
setCancelable
public void setCancelable(boolean cancelable) Whether to show or hide Cancel button. -
setRejectable
public void setRejectable(boolean rejectable) Whether to show or hide Reject button. -
setRejectButton
public void setRejectButton(String buttonText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener) Sets Reject button text and `reject` event listener. Makes Reject button visible- Parameters:
buttonText- the text inside Reject buttonrejectListener- the event listener for `reject` event
-
setRejectButton
public void setRejectButton(String buttonText, ComponentEventListener<ConfirmDialog.RejectEvent> rejectListener, String theme) Sets Reject button text, `reject` event listener, Reject button theme. Makes Reject button visible- Parameters:
buttonText- the text inside Reject buttonrejectListener- the event listener for `reject` eventtheme- the theme applied for a Reject button
-
setRejectButton
Sets custom Reject button- Parameters:
component- the component to display instead of default Reject button
-
setRejectButton
Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedSets custom Reject button- Parameters:
element- the element to display instead of default Reject button
-
setCancelButton
public void setCancelButton(String buttonText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener) Sets Cancel button text and `cancel` event listener. Makes Cancel button visible- Parameters:
buttonText- the text inside Cancel buttoncancelListener- the event listener for `cancel` event
-
setCancelButton
public void setCancelButton(String buttonText, ComponentEventListener<ConfirmDialog.CancelEvent> cancelListener, String theme) Sets Cancel button text, `cancel` event listener and Cancel button theme. Makes Cancel button visible- Parameters:
buttonText- the text inside Cancel buttoncancelListener- the event listener for `cancel` eventtheme- the theme applied for a Cancel button
-
setCancelButton
Sets custom cancel button- Parameters:
component- the component to display instead of default Cancel button
-
setCancelButton
Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedSets custom cancel button- Parameters:
element- the element to display instead of default Cancel button
-
setConfirmButton
public void setConfirmButton(String buttonText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener) Sets Confirm button text and `confirm` event listener- Parameters:
buttonText- the text inside Confirm buttonconfirmListener- the event listener for `confirm` event
-
setConfirmButton
public void setConfirmButton(String buttonText, ComponentEventListener<ConfirmDialog.ConfirmEvent> confirmListener, String theme) Sets Confirm button text, `confirm` event listener and Confirm button theme- Parameters:
buttonText- the text inside Confirm buttonconfirmListener- the event listener for `confirm` eventtheme- the theme applied for a Confirm button
-
setConfirmButton
Sets custom confirm button- Parameters:
component- the component to display instead of default Confirm button
-
setConfirmButton
Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedSets custom confirm button- Parameters:
element- the element to display instead of default Confirm button
-
setText
Sets confirmation message text -
setText
Sets custom confirmation message- Parameters:
component- the component to display instead of default confirmation text node
-
setText
Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedSets custom confirmation message element- Parameters:
element- the element to display instead of default confirmation text node
-
setConfirmText
Sets Confirm button text -
setConfirmButtonTheme
Sets Confirm button theme -
addConfirmListener
Adds `confirm` event listener -
setCancelText
Sets Cancel button text -
setCancelButtonTheme
Sets Cancel button theme -
addCancelListener
Adds `cancel` event listener -
setRejectText
Sets Reject button text -
setRejectButtonTheme
Sets Reject button theme -
addRejectListener
Adds `reject` event listener -
setHeader
Sets confirmation dialog header text -
setHeader
Sets confirmation dialog custom header- Parameters:
component- the component to display instead of default header text
-
setHeader
Deprecated, for removal: This API element is subject to removal in a future version.Usage of Element API at Component level should be avoidedSets confirmation dialog custom header element- Parameters:
element- the element to display instead of default header text
-
open
public void open()Opens the dialog.If a dialog was not added manually to a parent component, it will be automatically added to the
UIwhen opened, and automatically removed from the UI when closed. Note that the dialog is then scoped to the UI, and not the current view. As such, when navigating away from a view, the dialog will still be opened or stay open. In order to close the dialog when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view. -
close
public void close()Closes the dialog.This automatically removes the dialog from the
UI, unless it was manually added to a parent component. -
isOpened
public boolean isOpened() -
setOpened
public void setOpened(boolean opened) Opens or closes the dialog.If a dialog was not added manually to a parent component, it will be automatically added to the
UIwhen opened, and automatically removed from the UI when closed. Note that the dialog is then scoped to the UI, and not the current view. As such, when navigating away from a view, the dialog will still be opened or stay open. In order to close the dialog when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view.- Parameters:
opened-trueto open the confirm-dialog,falseto close it
-
isCloseOnEsc
public boolean isCloseOnEsc()Gets whether this dialog can be closed by hitting the esc-key or not.By default, the dialog is closable with esc.
- Returns:
trueif this dialog can be closed with the esc-key,falseotherwise
-
setCloseOnEsc
public void setCloseOnEsc(boolean closeOnEsc) Sets whether this dialog can be closed by hitting the esc-key or not.By default, the dialog is closable with esc.
- Parameters:
closeOnEsc-trueto enable closing this dialog with the esc-key,falseto disable it
-
add
Deprecated.since v24.4, not supportedConfirm dialog does not support adding content. UsesetText(Component)instead to initialize content as a component.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
addin interfaceHasComponents- Parameters:
components- the components to add
-
add
Deprecated.since v24.4, not supportedConfirm dialog does not support adding content. UsesetText(Component)instead to initialize content as a component.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
addin interfaceHasComponents- Parameters:
components- the components to add
-
add
Deprecated.since v24.4, not supportedConfirm dialog does not support adding content. UsesetText(String)instead to initialize content as text.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
addin interfaceHasComponents- Parameters:
text- the text to add, notnull
-
remove
Deprecated.since v24.4, not supportedConfirm dialog does not support removing content.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
removein interfaceHasComponents- Parameters:
components- the components to remove
-
remove
Deprecated.since v24.4, not supportedConfirm dialog does not support removing content.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
removein interfaceHasComponents- Parameters:
components- the components to remove
-
removeAll
Deprecated.since v24.4, not supportedConfirm dialog does not support removing content.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
removeAllin interfaceHasComponents
-
addComponentAtIndex
Deprecated.since v24.4, not supportedConfirm dialog does not support adding content. UsesetText(Component)instead to initialize content as a component.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
addComponentAtIndexin interfaceHasComponents- Parameters:
index- the index, where the component will be added. The index must be non-negative and may not exceed the children countcomponent- the component to add, value should not be null
-
addComponentAsFirst
Deprecated.since v24.4, not supportedConfirm dialog does not support adding content. UsesetText(Component)instead to initialize content as a component.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
addComponentAsFirstin interfaceHasComponents- Parameters:
component- the component to add, value should not be null
-
replace
Deprecated.since v24.4, not supportedConfirm dialog does not support replacing content.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
replacein interfaceHasOrderedComponents- Parameters:
oldComponent- the old component that will be replaced. Can benull, which will make the newComponent to be added to the layout without replacing any othernewComponent- the new component to be replaced. Can benull, which will make the oldComponent to be removed from the layout without adding any other
-
indexOf
Deprecated.since v24.4, not supportedConfirm dialog does not support multiple components.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
indexOfin interfaceHasOrderedComponents- Parameters:
component- the component to look up, can not benull- Returns:
- the index of the component or -1 if the component is not a child
-
getComponentCount
Deprecated.since v24.4, not supportedConfirm dialog does not support multiple components.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
getComponentCountin interfaceHasOrderedComponents- Returns:
- the number of components
-
getComponentAt
Deprecated.since v24.4, not supportedConfirm dialog does not support multiple components.This method is inherited from
HasOrderedComponentsand has been marked as deprecated to indicate that it is not supported.- Specified by:
getComponentAtin interfaceHasOrderedComponents- Parameters:
index- the position of the component, must be greater than or equals to 0 and less than the number of children components- Returns:
- The component at the given index
- See Also:
-
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.
-