com.vaadin.flow.component.confirmdialog.

Class ConfirmDialog

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.confirmdialog.ConfirmDialog

All Implemented Interfaces:

AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasOrderedComponents, HasSize, HasStyle, Serializable

@Tag("vaadin-confirm-dialog") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.1") @NpmPackage(value="@vaadin/confirm-dialog",version="24.7.1") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/confirm-dialog/src/vaadin-confirm-dialog.js") public class ConfirmDialog extends Component implements HasSize, HasStyle, HasOrderedComponents

Confirm Dialog is a modal Dialog used to confirm user actions.

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:

  • Constructor Details

  • Method Details

    • getWidth

      public String getWidth()

      Description copied from interface: HasSize

      Gets 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).

      Specified by:

      getWidth in interface HasSize

      Returns:

      the width which has been set for the component

    • setWidth

      public void setWidth(String width)

      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 width value is null then width is removed.

      Specified by:

      setWidth in interface HasSize

      Parameters:

      width - the width to set, may be null

    • getHeight

      public String getHeight()

      Description copied from interface: HasSize

      Gets 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).

      Specified by:

      getHeight in interface HasSize

      Returns:

      the height which has been set for the component

    • setHeight

      public void setHeight(String height)

      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 height value is null then height is removed.

      Specified by:

      setHeight in interface HasSize

      Parameters:

      height - the height to set, may be null

    • setClassName

      public void setClassName(String className)

      Sets the CSS class names of the dialog overlay element. This method overwrites any previous set class names.

      Specified by:

      setClassName in interface HasStyle

      Parameters:

      className - a space-separated string of class names to set, or null to remove all class names

    • getClassNames

      public ClassList getClassNames()

      Description copied from interface: HasStyle

      Gets 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 the class attribute.

      Despite the name implying a list being returned, the return type is actually a Set since the in-browser return value behaves like a Set in Java.

      Specified by:

      getClassNames in interface HasStyle

      Returns:

      a list of class names, never null

      See Also:

    • getStyle

      public Style getStyle()

      Description copied from interface: HasStyle

      Gets the style instance for managing inline styles for the element of this component.

      Specified by:

      getStyle in interface HasStyle

      Returns:

      the style object for the element, not null

      Throws:

      UnsupportedOperationException - ConfirmDialog does not support adding styles to overlay

    • setAriaDescribedBy

      public void setAriaDescribedBy(String describedBy)

      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

      public Optional<String> 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 button

      rejectListener - 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 button

      rejectListener - the event listener for `reject` event

      theme - the theme applied for a Reject button

    • setRejectButton

      public void setRejectButton(Component component)

      Sets custom Reject button

      Parameters:

      component - the component to display instead of default Reject button

    • setRejectButton

      @Deprecated(forRemoval=true) public void setRejectButton(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 avoided

      Sets 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 button

      cancelListener - 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 button

      cancelListener - the event listener for `cancel` event

      theme - the theme applied for a Cancel button

    • setCancelButton

      public void setCancelButton(Component component)

      Sets custom cancel button

      Parameters:

      component - the component to display instead of default Cancel button

    • setCancelButton

      @Deprecated(forRemoval=true) public void setCancelButton(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 avoided

      Sets 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 button

      confirmListener - 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 button

      confirmListener - the event listener for `confirm` event

      theme - the theme applied for a Confirm button

    • setConfirmButton

      public void setConfirmButton(Component component)

      Sets custom confirm button

      Parameters:

      component - the component to display instead of default Confirm button

    • setConfirmButton

      @Deprecated(forRemoval=true) public void setConfirmButton(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 avoided

      Sets custom confirm button

      Parameters:

      element - the element to display instead of default Confirm button

    • setText

      public void setText(String message)

      Sets confirmation message text

    • setText

      public void setText(Component component)

      Sets custom confirmation message

      Parameters:

      component - the component to display instead of default confirmation text node

    • setText

      @Deprecated(forRemoval=true) public void setText(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 avoided

      Sets custom confirmation message element

      Parameters:

      element - the element to display instead of default confirmation text node

    • setConfirmText

      public void setConfirmText(String confirmText)

      Sets Confirm button text

    • setConfirmButtonTheme

      public void setConfirmButtonTheme(String confirmTheme)

      Sets Confirm button theme

    • addConfirmListener

      public Registration addConfirmListener(ComponentEventListener<ConfirmDialog.ConfirmEvent> listener)

      Adds `confirm` event listener

    • setCancelText

      public void setCancelText(String cancelText)

      Sets Cancel button text

    • setCancelButtonTheme

      public void setCancelButtonTheme(String cancelTheme)

      Sets Cancel button theme

    • addCancelListener

      public Registration addCancelListener(ComponentEventListener<ConfirmDialog.CancelEvent> listener)

      Adds `cancel` event listener

    • setRejectText

      public void setRejectText(String rejectText)

      Sets Reject button text

    • setRejectButtonTheme

      public void setRejectButtonTheme(String rejectTheme)

      Sets Reject button theme

    • addRejectListener

      public Registration addRejectListener(ComponentEventListener<ConfirmDialog.RejectEvent> listener)

      Adds `reject` event listener

    • setHeader

      public void setHeader(String header)

      Sets confirmation dialog header text

    • setHeader

      public void setHeader(Component component)

      Sets confirmation dialog custom header

      Parameters:

      component - the component to display instead of default header text

    • setHeader

      @Deprecated(forRemoval=true) public void setHeader(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 avoided

      Sets confirmation dialog custom header element

      Parameters:

      element - the element to display instead of default header text

    • open

      public void open()

      Opens the dialog.

      Note: You don't need to add the dialog component before opening it, cause opening a dialog will automatically add it to the <body> if it's not yet attached anywhere.

    • close

      public void close()

      Closes the dialog.

      Note: This method also removes the dialog component from the DOM after closing it, unless you have added the component manually.

    • isOpened

      public boolean isOpened()
    • setOpened

      public void setOpened(boolean opened)

      Opens or closes the dialog.

      Note: Confirm-dialog will be attached or detached from the DOM automatically, if it was not added manually.

      Parameters:

      opened - true to open the confirm-dialog, false to 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:

      true if this dialog can be closed with the esc-key, false otherwise

    • 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 - true to enable closing this dialog with the esc-key, false to disable it

    • add

      @Deprecated public void add(Component... components)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support adding content. Use setText(Component) instead to initialize content as a component.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      add in interface HasComponents

      Parameters:

      components - the components to add

    • add

      @Deprecated public void add(Collection<Component> components)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support adding content. Use setText(Component) instead to initialize content as a component.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      add in interface HasComponents

      Parameters:

      components - the components to add

    • add

      @Deprecated public void add(String text)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support adding content. Use setText(String) instead to initialize content as text.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      add in interface HasComponents

      Parameters:

      text - the text to add, not null

    • remove

      @Deprecated public void remove(Component... components)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support removing content.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      remove in interface HasComponents

      Parameters:

      components - the components to remove

    • remove

      @Deprecated public void remove(Collection<Component> components)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support removing content.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      remove in interface HasComponents

      Parameters:

      components - the components to remove

    • removeAll

      @Deprecated public void removeAll()
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support removing content.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      removeAll in interface HasComponents

    • addComponentAtIndex

      @Deprecated public void addComponentAtIndex(int index, Component component)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support adding content. Use setText(Component) instead to initialize content as a component.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      addComponentAtIndex in interface HasComponents

      Parameters:

      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count

      component - the component to add, value should not be null

    • addComponentAsFirst

      @Deprecated public void addComponentAsFirst(Component component)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support adding content. Use setText(Component) instead to initialize content as a component.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      addComponentAsFirst in interface HasComponents

      Parameters:

      component - the component to add, value should not be null

    • replace

      @Deprecated public void replace(Component oldComponent, Component newComponent)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support replacing content.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      replace in interface HasOrderedComponents

      Parameters:

      oldComponent - the old component that will be replaced. Can be null, which will make the newComponent to be added to the layout without replacing any other

      newComponent - the new component to be replaced. Can be null, which will make the oldComponent to be removed from the layout without adding any other

    • indexOf

      @Deprecated public int indexOf(Component component)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support multiple components.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      indexOf in interface HasOrderedComponents

      Parameters:

      component - the component to look up, can not be null

      Returns:

      the index of the component or -1 if the component is not a child

    • getComponentCount

      @Deprecated public int getComponentCount()
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support multiple components.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      getComponentCount in interface HasOrderedComponents

      Returns:

      the number of components

    • getComponentAt

      @Deprecated public Component getComponentAt(int index)
      Deprecated.
      since v24.4, not supported

      Confirm dialog does not support multiple components.

      This method is inherited from HasOrderedComponents and has been marked as deprecated to indicate that it is not supported.

      Specified by:

      getComponentAt in interface HasOrderedComponents

      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

      protected void onAttach(AttachEvent attachEvent)

      Description copied from class: Component

      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component.

      Make sure to call super.onAttach when overriding this method.

      Overrides:

      onAttach in class Component

      Parameters:

      attachEvent - the attach event