Question

There are some options to open a new page or redirect page in GWT, & I don't know which one is the best?

-Option 1: will redirect the current page to a new page but not opening a new tab.

String url = Window.Location.createUrlBuilder().setHash("!search").buildString();
Window.Location.assign(url);

-Option 2: open a new page on a new tab.

String url = Window.Location.createUrlBuilder().setHash("!search").buildString();
Window.open(url, "_blank", null);

-Option 3: will redirect the current page to a new page but not opening a new tab & retain the states of the previous page

PlaceRequest request=new PlaceRequest(NameTokens.search);
placeManager.revealPlace(request);

In Option 1 & 2, it seems that the system starts to reload the whole page. For option 2, if you press Back button then it will reload the previous page again.

In Option 3, it seems that it does not reload the whole page (ie if you have a header then it won't download the header again). Therefore, it run very fast. If you click Back button then it won't reload the previous page so you can still see all the existing states of the previous page.

Option 3 is quite fast. However, we need to properly reset some variables in the previous page otherwise it will make thing really messy and error-prone.

What is the best practice for open a new page or redirect page in GWT? Which option should we use?

Was it helpful?

Solution

Option 1

Whenever you reload the page, your app has to reload as well. It may happen fast, as the browser caches your code and other static elements, but what is the point? GWT is used as an "app": it resides within a single host page, and changes its state based on user instructions.

Window.Location.assign(url) is only used when a user is leaving your application: either because this user logged out, or because he is not logged in yet, and you redirect him to a login page.

Option 2

Usually, this option is used when you provide a link to a different application/website, and you want to keep your app running.

Option 3

In this option you do not "redirect" "pages". You show different "views" to a user. The web page (host page) remains the same at all times. This is how GWT is supposed to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top