Reputation: 13
I tried to get the last visited page in my GWT application. I want to skip particular page if that comes in history. To get last visited page, I tried History.getToken()
to get current token as described in docs. But it is always returning blank token.
Please help. I am beginner level developer at GWT.
Upvotes: 1
Views: 952
Reputation: 46841
Please have a look at Coding Basics History - GWT Project.
For example, a history token named page1
would be added to a URL as follows:
http://www.example.com/com.example.gwt.HistoryExample/HistoryExample.html#page1
When the application wants to push a placeholder onto the browser's history stack, it simply invokes History.newItem(token).
When the user uses the back button, a call will be made to any object that was added as a handler with History.addValueChangeHandler().
It is up to the application to restore the state according to the value of the new token.
Please validate below points in your application.
To use GWT History support, you must first embed an iframe
into your host HTML page.
<iframe src="javascript:''"
id="__gwt_historyFrame"
style="position:absolute;width:0;height:0;border:0"></iframe>
Then, in your GWT application, perform the following steps:
ValueChangeEvent.getValue()
) and changes the application state to match.Question : GWT - History.getToken()
is always returning blank value?
Please check the URL again and confirm that you have added new history tokens to the history stack and most important is to include the history frame in your host page.
Look at the source code to understand that why you are getting blank value?
// History.class
public class History {
private static HistoryImpl impl;
static {
impl = GWT.create(HistoryImpl.class);
if (!impl.init()) {
// Set impl to null as a flag to no-op future calls.
impl = null;
// Tell the user.
GWT.log("Unable to initialize the history subsystem; did you "
+ "include the history frame in your host page? Try "
+ "<iframe src=\"javascript:''\" id='__gwt_historyFrame' "
+ "style='position:absolute;width:0;height:0;border:0'>"
+ "</iframe>");
}
}
public static String getToken() {
// impl is null if you have not included the history frame in your host page
// if impl is null then it return blank value
return impl != null ? HistoryImpl.getToken() : "";
}
}
Find a sample code here on History Management in GWT.
Upvotes: 1