abhishekgarg
abhishekgarg

Reputation: 164

Timer is not working in GWT,

I am redirecting some other web page when execution finishes on my side. I want to display message to my user that we are "redirecting in %d seconds" for that I used Timer class,but it is still redirecting instantly.

Code is below.

 public void redirect(){
      hanldeWait() ;
       Window.Location.assign(Url) ;
 }

   private void hanldeWait(){
    Timer timer = new Timer() {
        int i = 5 ;
        public void run() {
            if(i < 0){
                errorMessage.setVisible(false);
                cancel() ;
            }else{
                i-- ;
                String redirectionMessage = "Redirecting in %d seconds" ;
                String displayMessage = redirectionMessage ;

                displayMessage  = format(redirectionMessage, (Integer)i) ;
                errorMessage.setText(displayMessage);
                errorMessage.setVisible(true);

            }
        }
      };
      timer.scheduleRepeating(5000) ;
}

If i am doing something wrong here.

Upvotes: 1

Views: 314

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

Your code tells the browser to redirect immediately, with no delay.

If you want to redirect after a delay, then

Window.Location.assign(Url) ;

should be called inside the run method of a Timer.

Upvotes: 2

Related Questions