GWT历史中需要什么History.fireCurrentHistoryState()? [英] What is need History.fireCurrentHistoryState() in GWT History?

查看:103
本文介绍了GWT历史中需要什么History.fireCurrentHistoryState()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在研究一个GWT样本历史管理应用程序。
这是我的onModuleLoad代码。

  public void onModuleLoad(){
ContentPanel panel = ContentPanel.getInstance ();
if(History.getToken()!= null&& History.getToken()。length()== 0)
{
History.newItem(first_page);
}
History.addValueChangeHandler(new HistoryHandler());
RootPanel.get()。add(panel);
History.fireCurrentHistoryState();



$ b $ p
$ b $ p $在这个例子中我触发了History.fireCurrentHistoryState();激发当前的历史状态。
现在在我的firstPanel类中,它是名为第二个面板的按钮,其中的历史令牌second_page被触发。

  public FirstPanel ){
VerticalPanel面板=新的VerticalPanel();
按钮button2 =新建按钮(Second Panel);
button2.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
History.newItem(second_page);
}
});
panel.add(button2);
initWidget(panel);
}

但是这里不需要激活History.fireCurrentHistoryState();再次。
简单histt​​ory.newItem工作正常。



现在我想知道在模块加载时只需要History.fireCurrentHistoryState()是什么?
也是为什么它不是第二次在应用程序中需要。

解决方案

历史记录。 fireCurrentHistoryState()调用您的历史处理程序,而不实际在浏览器历史堆栈中插入新的历史记录,而 History.newItem(令牌)进入历史堆栈。



注意:如果您的当前令牌与新令牌相同(即重新加载相同页面),则浏览器不会将其插入历史堆栈。在这种情况下(当前令牌==新令牌) History.fireCurrentHistoryState()具有相同的效果History.newItem(currentToken)


Hello I am working on a GWT sample history management application. Here is my onModuleLoad Code.

public void onModuleLoad() {
    ContentPanel panel = ContentPanel.getInstance();
    if(History.getToken()!=null && History.getToken().length()==0)
    {
        History.newItem("first_page");
    }
    History.addValueChangeHandler(new HistoryHandler());
    RootPanel.get().add(panel);
    History.fireCurrentHistoryState();
}

In this I fired History.fireCurrentHistoryState(); to fire current state of history. Now In my firstPanel class ther is button named Second Panel on which history token second_page is fired.

public FirstPanel() {
    VerticalPanel panel = new VerticalPanel();
    Button button2 = new Button("Second Panel");
    button2.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            History.newItem("second_page");
        }
    });
    panel.add(button2);
    initWidget(panel);
}

But here no need to fire History.fireCurrentHistoryState() ; again. simply histtory.newItem works fine.

Now I want to know that what the need of History.fireCurrentHistoryState() at module load time only? Also why it is not required second time in the application.?

解决方案

History.fireCurrentHistoryState() invokes your history handlers without actually inserting new history item in browser history stack, while History.newItem(token) does insert new history token into history stack.

Note: if your current token is the same as new token (i.e. same page is reloaded), then browsers do not insert this into history stack. In this case (current token == new token) History.fireCurrentHistoryState() has the same effect as History.newItem(currentToken).

这篇关于GWT历史中需要什么History.fireCurrentHistoryState()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆