/**
* Enables or disables the notification. If disabled, the set URL (or
- * current) is loaded directly.
+ * current) is loaded directly when next transaction between server and
+ * client happens.
*
* @param sessionExpiredNotificationEnabled
- * true = enabled, false = disabled
+ * true = enabled, false = disabled
*/
public void setSessionExpiredNotificationEnabled(
boolean sessionExpiredNotificationEnabled) {
/**
* Sets the caption of the notification. Set to null for no caption. If
- * both caption and message is null, the notification is disabled;
+ * both caption and message are null, client automatically forwards to
+ * sessionExpiredUrl after timeout timer expires. Timer uses value read
+ * from HTTPSession.getMaxInactiveInterval()
*
* @param sessionExpiredCaption
* the caption
/**
* Sets the message of the notification. Set to null for no message. If
- * both caption and message is null, the notification is disabled;
+ * both caption and message are null, client automatically forwards to
+ * sessionExpiredUrl after timeout timer expires. Timer uses value read
+ * from HTTPSession.getMaxInactiveInterval()
*
* @param sessionExpiredMessage
- * the message
+ * the message
*/
public void setSessionExpiredMessage(String sessionExpiredMessage) {
this.sessionExpiredMessage = sessionExpiredMessage;
/** List of pending variable change bursts that must be submitted in order */
private final Vector pendingVariableBursts = new Vector();
+
+ /** Timer for automatic refirect to SessionExpiredURL */
+ private Timer redirectTimer;
+
+ /** redirectTimer scheduling interval in seconds */
+ private int sessionExpirationInterval;
public ApplicationConnection(WidgetSet widgetSet,
ApplicationConfiguration cnf) {
idToPaintable.clear();
paintableToId.clear();
}
+ if (meta.containsKey("timedRedirect")) {
+ final JSONObject timedRedirect = meta.get("timedRedirect").isObject();
+ redirectTimer = new Timer() {
+ public void run() {
+ redirect(timedRedirect.get("url").isString().stringValue());
+ }
+ };
+ sessionExpirationInterval = Integer.parseInt(timedRedirect.get("interval").toString());
+ }
+ }
+ if (redirectTimer != null) {
+ redirectTimer.schedule(1000 * sessionExpirationInterval);
}
-
// Process changes
final JSONArray changes = (JSONArray) ((JSONObject) json)
.get("changes");
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
private int pendingLocalesIndex;
+ private int timeoutInterval = -1;
+
public CommunicationManager(Application application,
ApplicationServlet applicationServlet) {
this.application = application;
outWriter.write("\"repaintAll\":true");
}
+ SystemMessages ci = null;
+ try {
+ Method m = application.getClass().getMethod(
+ "getSystemMessages", null);
+ ci = (Application.SystemMessages) m.invoke(null, null);
+ } catch (NoSuchMethodException e1) {
+ e1.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+
+ // meta instruction for client to enable auto-forward to
+ // sessionExpiredURL after timer expires.
+ if (ci != null && ci.getSessionExpiredMessage() == null
+ && ci.getSessionExpiredCaption() == null
+ && ci.isSessionExpiredNotificationEnabled()) {
+ int newTimeoutInterval = request.getSession()
+ .getMaxInactiveInterval();
+ if (repaintAll || (timeoutInterval != newTimeoutInterval)) {
+ String escapedURL = ci.getSessionExpiredURL() == null ? ""
+ : ci.getSessionExpiredURL().replace("/", "\\/");
+ if (metaOpen) {
+ outWriter.write(",");
+ }
+ outWriter.write("\"timedRedirect\":{\"interval\":"
+ + (newTimeoutInterval + 15) + ",\"url\":\""
+ + escapedURL + "\"}");
+ metaOpen = true;
+ }
+ timeoutInterval = newTimeoutInterval;
+ }
+
// add meta instruction for client to set focus if it is set
final Paintable f = (Paintable) application.consumeFocus();
if (f != null) {
--- /dev/null
+package com.itmill.toolkit.tests.tickets;
+
+import java.util.Date;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+public class Ticket2106 extends Application {
+
+ private static CustomizedSystemMessages msgs = new Application.CustomizedSystemMessages();
+ static {
+ // We will forward the user to www.itmill.com when the session expires
+ msgs.setSessionExpiredURL("http://www.itmill.com");
+ msgs.setSessionExpiredMessage(null);
+ msgs.setSessionExpiredCaption(null);
+ }
+
+ public static Application.SystemMessages getSystemMessages() {
+ return msgs;
+ }
+
+ public void init() {
+ setMainWindow(new Window("#2106"));
+ getMainWindow().addComponent(
+ new Button("Do nothing", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ getMainWindow().addComponent(
+ new Label("Last time did nothing: "
+ + new Date()));
+ }
+ }));
+ }
+
+}