Class WTimeoutWarning

  • All Implemented Interfaces:
    WComponent, WebComponent, Serializable

    public class WTimeoutWarning
    extends AbstractWComponent
    WTimeoutWarning provides a mechanism to pass a session timeout period in seconds to the client. This can then be used to indicate to the user when their session is about to expire.

    This has two purposes: firstly it provides a means to minimise data loss by users by indicating that they should submit their work before the session expires; and secondly it is a WCAG requirement that users be given a warning of the end of a time-limited process and a means to extend that limit.

    If the timeout period is "zero", then use the http session timeout interval will be used. If a user's session does not expire then an existing WTimeoutWarning can have its timeout set to -1. This will prevent painting the WTimeoutWarning. This value is the equivalent of a http session time out value of -1 which indicates that the session does not time out.

    Since:
    1.0.0
    Author:
    Mark Reeves
    See Also:
    Serialized Form
    • Constructor Detail

      • WTimeoutWarning

        public WTimeoutWarning()
        Creates a WTimeoutWarning using default timeout and warning settings.
      • WTimeoutWarning

        public WTimeoutWarning​(int timeoutPeriod,
                               int warningPeriod)
        Creates a timeout indicator with both a timeout period and warning period

        If the timeout period is "zero", then use the http session timeout interval will be used.

        Parameters:
        timeoutPeriod - The timeout in seconds. This should be slightly less than the shortest timeout period in the entire application stack, not just the web server session timeout.
        warningPeriod - The time in seconds before the time out occurs in which the warning indicator should show. There is a minimum for this which is determined by the Web Content Accessibility Guidelines 2.0.
      • WTimeoutWarning

        public WTimeoutWarning​(int timeoutPeriod)
        Creates a timeout indicator with a timeout period and uses the default warning period.

        If the timeout period is "zero", then use the http session timeout interval will be used.

        Parameters:
        timeoutPeriod - The timeout in seconds.
    • Method Detail

      • setTimeoutPeriod

        public void setTimeoutPeriod​(int timeoutPeriod)
        Set a timeout indicator for a specified number of seconds.

        If the timeout period is "zero", then the session timeout interval will be used.

        Parameters:
        timeoutPeriod - the timeout in seconds.
      • setWarningPeriod

        public void setWarningPeriod​(int warningPeriod)
        Set a pre-timeout warning to a specified number of seconds. This should be no less than the WCAG minimum of 20.

        Setting the warning period to exactly ZERO (0) allows the warning time to be determined in the client layer.

        Parameters:
        warningPeriod - The timeout warning will show this many seconds before the timeout as indicated by the timeoutPeriod.
      • getTimeoutPeriod

        public int getTimeoutPeriod()
        Get the indicated timeout period.
        Returns:
        The timeout period in seconds.
      • getWarningPeriod

        public int getWarningPeriod()
        Get the warning period.
        Returns:
        The warning period in seconds.
      • preparePaintComponent

        protected void preparePaintComponent​(Request request)
        Initialise by setting the timeout to the HTTPSession maxInactiveInterval if the timeoutPeriod has not yet been set. Subclasses may override this method to place the component in the correct state before it is painted. When overriding this method, it is good practice to also call the superclass implementation.
        Overrides:
        preparePaintComponent in class AbstractWComponent
        Parameters:
        request - the request being responded to.
      • getOrCreateComponentModel

        protected WTimeoutWarning.TimeoutWarningModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractWComponent
        Returns:
        the model for this component