GWT: how do I go to a new place from within the Activity start method?

偶尔善良 提交于 2019-12-24 15:22:13

问题


So I'm doing something like this:

public class SecureActivity extends AbstractActivity {
  public void start(AcceptsOneWidget container, EventBus eventBus) {    
    if (!_app.isUserLoggedIn()) {
      _app.goTo(new LoginPlace(_app.getCurrentPlaceToken()))
    } else {
      // do cool secure stuff
    }
  }
}

But the behavior that I'm seeing is that my browser's history is for original url (from the original request), then the login:redirectPlace, and then original url again.

It seems like I need to do my redirection after the start() method has completed. Is there a proper way to delay/delegate that goTo to happen outside of the start method?

Thanks.


回答1:


That should be enough:

Scheduler.get().scheduleFinally(new ScheduledCommand() {
   @Override
   public void execute() {
      _app.goTo(new LoginPlace(_app.getCurrentPlaceToken());
   }
}


来源:https://stackoverflow.com/questions/8003229/gwt-how-do-i-go-to-a-new-place-from-within-the-activity-start-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!