Class IdleNotification

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.componentfactory.IdleNotification
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, Serializable

@Tag("idle-notification") @JsModule("./idle-notification.js") @CssImport("./idle-notification.css") @CssImport(value="./vaadin-dialog-overlay.css",themeFor="vaadin-dialog-overlay") @Uses(com.vaadin.flow.component.dialog.Dialog.class) public class IdleNotification extends com.vaadin.flow.component.Component
See Also:
  • Field Details

    • DEFAULT_SECONDS_BEFORE_NOTIFICATION

      public static final int DEFAULT_SECONDS_BEFORE_NOTIFICATION
      See Also:
    • DEFAULT_BEFORE_EXPIRE_MESSAGE

      public static final String DEFAULT_BEFORE_EXPIRE_MESSAGE
    • DEFAULT_AFTER_EXPIRE_MESSAGE

      public static final String DEFAULT_AFTER_EXPIRE_MESSAGE
      See Also:
  • Constructor Details

    • IdleNotification

      public IdleNotification() throws IllegalArgumentException
      Default constructor. Creates an idle notification with defaults.

      maxInactiveInterval is obtained via VaadinSession.getCurrent().getSession().getMaxInactiveInterval()

      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • IdleNotification

      public IdleNotification(int secondsBeforeNotification) throws IllegalArgumentException
      Creates an idle notification with the default message that will be displayed to the user at the specified number of seconds before session timeout.

      maxInactiveInterval is obtained via VaadinSession.getCurrent().getSession().getMaxInactiveInterval()

      Parameters:
      secondsBeforeNotification - the number of seconds before session times-out at which point the notification will be displayed to the user
      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • IdleNotification

      public IdleNotification(String message, int secondsBeforeNotification) throws IllegalArgumentException
      Creates an idle notification with the specified message that will be displayed to the user at the specified number of seconds before session timeout.

      maxInactiveInterval is obtained via VaadinSession.getCurrent().getSession().getMaxInactiveInterval()

      Parameters:
      message - the text of the notification
      secondsBeforeNotification - the number of seconds before session times-out at which point the notification will be displayed to the user
      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • IdleNotification

      public IdleNotification(String message, int secondsBeforeNotification, String redirectAtTimeoutUrl) throws IllegalArgumentException
      Creates an idle notification with the specified message that will be displayed to the user at the specified number of seconds before session timeout.

      maxInactiveInterval is obtained via VaadinSession.getCurrent().getSession().getMaxInactiveInterval()

      Parameters:
      message - the text of the notification
      secondsBeforeNotification - the number of seconds before session times-out at which point the notification will be displayed to the user
      redirectAtTimeoutUrl - The URL to redirect the page to upon session timeout
      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • IdleNotification

      public IdleNotification(String message, int secondsBeforeNotification, int maxInactiveInterval, String redirectAtTimeoutUrl) throws IllegalArgumentException
      Creates an idle notification with the specified message that will be displayed to the user at the specified number of seconds before session timeout. This constructor allows the specification of an arbitrary maxInactiveInterval, which doesn't have to coincide with the one defined for the underlying HttpSession.
      Parameters:
      message - the text of the notification
      secondsBeforeNotification - the number of seconds before session times-out at which point the notification will be displayed to the user
      maxInactiveInterval - the number of seconds until the session times-out
      redirectAtTimeoutUrl - The URL to redirect the page to upon session timeout
      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • IdleNotification

      public IdleNotification(String message, int secondsBeforeNotification, int maxInactiveInterval) throws IllegalArgumentException
      Creates an idle notification with the specified message that will be displayed to the user at the specified number of seconds before session timeout. This constructor allows the specification of an arbitrary maxInactiveInterval, which doesn't have to coincide with the one defined for the underlying HttpSession.
      Parameters:
      message - the text of the notification
      secondsBeforeNotification - the number of seconds before session times-out at which point the notification will be displayed to the user
      maxInactiveInterval - the number of seconds until the session times-out
      Throws:
      IllegalArgumentException - If either secondsBeforeNotification or maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
  • Method Details

    • addCloseButton

      public void addCloseButton()
      Adds a button to close the notification without poking the server
    • removeCloseButton

      public void removeCloseButton()
      Remove the close Button
    • getMessage

      public String getMessage()
      Get the text of the notification
      Returns:
      the text of the notification
    • setMessage

      public void setMessage(String message)
      Set the text of the notification with given String

      NOTE: IdleNotification.MessageFormatting can be used to format the message

      Parameters:
      message - the text of the Notification
    • addExtendSessionButton

      public void addExtendSessionButton(String caption)
      Add a button to the notification that allows the user to poke the server, thereby extending the session
    • removeExtendSessionButton

      public void removeExtendSessionButton()
      Remove the extend-session button
    • addRedirectButton

      public void addRedirectButton(String caption, String url)
      Add a button to the notification that allows the user to be immediately redirected to a different url (e.g. a logout url)
    • removeRedirectButton

      public void removeRedirectButton()
      Remove the redirect button
    • getRedirectAtTimeoutUrl

      public String getRedirectAtTimeoutUrl()
      Get the URL to redirect the page to upon session timeout
    • setRedirectAtTimeoutUrl

      public void setRedirectAtTimeoutUrl(String redirectAtTimeoutUrl)
      The URL to redirect the page to upon session timeout. Setting this value to null will disable URL redirection upon timeout
    • getAfterExpiredMessage

      public String getAfterExpiredMessage()
      Get the message displayed to the user after the session expires
    • setAfterExpiredMessage

      public void setAfterExpiredMessage(String afterExpiredMessage)
      Set the message displayed to the user after the session expires

      NOTE: this message would only be displayed if redirectAtTimeoutUrl is not set

    • getMaxInactiveInterval

      public int getMaxInactiveInterval()
      Get the number of seconds until the session times-out

      NOTE: This getter's return value doesn't have to coincide with the one defined for the underlying HttpSession.

    • setMaxInactiveInterval

      public void setMaxInactiveInterval(int maxInactiveInterval) throws IllegalArgumentException
      Set the number of seconds until the session times-out

      NOTE: This setter allows the specification of an arbitrary maxInactiveInterval, which doesn't have to coincide with the one defined for the underlying HttpSession.

      Throws:
      IllegalArgumentException - If maxInactiveInterval value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • getSecondsBeforeNotification

      public int getSecondsBeforeNotification()
      Gets the number of seconds before session times-out at which point the notification will be displayed to the user
    • setSecondsBeforeNotification

      public void setSecondsBeforeNotification(int secondsBeforeNotification) throws IllegalArgumentException
      Sets the number of seconds before session times-out at which point the notification will be displayed to the user
      Throws:
      IllegalArgumentException - If secondsBeforeNotification value is smaller than 1 seconds, or if secondsBeforeNotification value is larger than, or equal to, maxInactiveInterval.
    • isExtendSessionOnOutsideClick

      public boolean isExtendSessionOnOutsideClick()
    • setExtendSessionOnOutsideClick

      public void setExtendSessionOnOutsideClick(boolean extendSessionOnOutsideClick)
      Determines whether an outside click would poke the server (thereby extending the session)
    • isCloseNotificationOnOutsideClick

      public boolean isCloseNotificationOnOutsideClick()
    • setCloseNotificationOnOutsideClick

      public void setCloseNotificationOnOutsideClick(boolean closeNotificationOnOutsideClick)
      Determines whether an outside click would close the notification without poking the server

      NOTE: this would only have an effect if (extendSessionOnOutsideClick == false)

    • addOpenListener

      public com.vaadin.flow.shared.Registration addOpenListener(com.vaadin.flow.component.ComponentEventListener<IdleNotification.OpenEvent> listener)
      Adds a open handler
    • addCloseListener

      public com.vaadin.flow.shared.Registration addCloseListener(com.vaadin.flow.component.ComponentEventListener<IdleNotification.CloseEvent> listener)
      Adds a close handler
    • addExtendSessionListener

      public com.vaadin.flow.shared.Registration addExtendSessionListener(com.vaadin.flow.component.ComponentEventListener<IdleNotification.ExtendSessionEvent> listener)
      Adds a session extend handler
    • addRedirectListener

      public com.vaadin.flow.shared.Registration addRedirectListener(com.vaadin.flow.component.ComponentEventListener<IdleNotification.RedirectEvent> listener)
      Adds a redirect handler
    • addTimeoutListener

      public com.vaadin.flow.shared.Registration addTimeoutListener(com.vaadin.flow.component.ComponentEventListener<IdleNotification.TimeoutEvent> listener)
      Adds a timeout handler