0

アプリケーションに GWT タイマーがあり、15 分ごとにトリガーする必要があります。これは一般的にうまく機能しています。ただし、GwtFileuploadダイアログ ボックスが開いていると、TIMER がトリガーされません。

以下は、私の問題を示すサンプル アプリケーションです。ここでは、分ごとにタイマーをスケジュールしました。開いたボックスButtonの[ファイルの選択] をクリックします。1 分以上開いたままにします。タイマーはトリガーされません。IE8/9/10 でこのサンプル コードを確認しました。引き金になった。FileuploadFileUpload Dialog

どんな助けでも大歓迎です

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class FileuploadEx implements EntryPoint{

@Override
public void onModuleLoad() {
    // TODO Auto-generated method stub
    FileUpload upload = new FileUpload();
    upload.setName("Select File..");
    VerticalPanel panel = new VerticalPanel();
    panel.add(upload);
    RootPanel.get().add(panel);
    Timer t = new Timer() {

        @Override
        public void run() {
            runAlert();
        }
    };
    t.schedule(60000);
}

public void runAlert(){
    Window.alert("Timer triggered");
    Timer t = new Timer() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            runAlert();
        }
    };
    t.schedule(60000);
}
}
4

1 に答える 1

2

Javascript is single threaded, so certain dialogs like alert and confirm stops the main thread and timers are not going to be executed until the dialog closes.

However file-browser normally does not stop the thread ant least in the browsers I've tested (chrome and FF in linux), so it could be an issue in your browser or your os.

Check this example of gwtupload, and you can see that when you are uploading a big file (about 800Mb because the example is limited to 1Mb) and you open the browser selector the progress bar, which actually uses timers and ajax, continues updating.

[EDITED] After spending a bit more time testing browsers, modern browsers work, except IE which always stops the javascript thread.

I guess there is no solution to the problem unless Microsoft modifies their product. So the best thing you can do in your code is to expire the session when the file selector closes.

Related with your problem to expire the session, I would do in this order:

  1. Expire the session in server side based on inactivity or a fixed periode, so as when the client asks the server it will get an error and would bring the user to the login screen or whatever. This is the method more reliable and more widely used.

  2. If you want to go with JS, set the start time of the session in a var, and then run a periodic timer to check whether the session has expired. When the file dialog is opened, the timer does not run, but as soon as the user closes the dialog it will get the message of session expired

    final double limit = 1000 * 60 * 15; // 15 minutes
    final double started = Duration.currentTimeMillis();

    Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
        public boolean execute() {
            double now = Duration.currentTimeMillis();
            if (now - started > limit) {
                // your code to remove session objects here
                Window.alert("Session expired");
                return false;
            }
            return true;
        }
    }, 1000);
于 2013-10-19T18:51:15.113 に答える