简体   繁体   English

GWT历史记录-为什么它会改变屏幕的焦点?

[英]GWT History - Why does it change the focus of my screen?

I have a simple application structure that will contain three composites at any one time - my header, footer and content composites. 我有一个简单的应用程序结构,该结构可以随时包含三个组合-我的页眉,页脚和内容组合。 The composites are laid out in the follow manner. 复合材料按以下方式布置。

<body>
    <div id="header">
    <div id="content">
    <div id="footer">
</body>

The composites are assigned to the three <div> 's in my EntryPoint . 组合在我的EntryPoint中分配给三个<div> The EntryPoint also contains a History Handler as follows. EntryPoint还包含一个历史记录处理程序,如下所示。

History.addValueChangeHandler(new ValueChangeHandler<String>() {
    @Override
    public void onValueChange(ValueChangeEvent<String> event) {
        String historyToken = event.getValue();

        if(historyToken.isEmpty()) {
            parseTokens();
            ContentContainer.INSTANCE.setContent(new IndexScreen());
        }

        else if(historyToken.equalsIgnoreCase("registration")) {
            ContentContainer.INSTANCE.setContent(new RegisterScreen());
        }

        else if(historyToken.equalsIgnoreCase("login")) {
            ContentContainer.INSTANCE.setContent(new LoginScreen());
        }
    }
});

History.fireCurrentHistoryState();

In my Composites, I have several ClickEvent handlers that look similar to the following. 在我的Composites中,我有几个看起来类似于以下内容的ClickEvent处理程序。

@UiHandler("registerLink")
public void handleClick(ClickEvent event) {
    ContentContainer.INSTANCE.setContent(new RegisterScreen());
    History.newItem("registration", true);
}

This registers the history very nicely. 这很好地记录了历史。 It also brings me to the appropriate pages when I click the back button. 单击后退按钮时,它也将我带到相应的页面。 However, it has the very odd effect of focusing the browser on the content composite, with the effect of the browser being scrolled to the bottom. 但是,将浏览器聚焦在内容复合上具有非常奇怪的效果,浏览器滚动到底部。 It's not a deal breaker but it kind of breaks the user experience a little. 这不是一个破坏交易的行为,但是会稍微破坏用户体验。 (Do let me know if the explanation isn't clear, I'll add images) (如果解释不清楚,请告诉我,我会添加图片)

What exactly is causing this and how can I fix it? 究竟是什么原因导致的?我该如何解决?

GWT history tokens work with the hash # token. GWT历史记录令牌与井号#令牌一起使用。 In html this was originally intended to use the browser to focus on a specific part of the page, if an element has a name or id with the string after the # token. 在html中,如果元素的nameid带有#标记后的字符串,则最初打算使用浏览器将其聚焦于页面的特定部分。 Could it be you have an id matching your history token? 可能是您的id与您的历史记录令牌匹配吗?

Also in you handleClick you call setContent . 同样在handleClick您调用setContent But if I'm correct the call after it triggers a change event and will end up in the onValueChange , which also calls the setContent . 但是,如果我在触发更改事件后正确调用,它将终止于onValueChange ,该onValueChange也调用setContent So it looks like you are calling setContent twice here. 因此,您似乎在这里两次调用了setContent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM