【问题标题】:Wicket AjaxEventBehavior with History API带有历史 API 的 Wicket AjaxEventBehavior
【发布时间】:2017-10-03 16:32:52
【问题描述】:

我正在使用带有 History API 的 Wicket 7.x。我目前正在尝试为“onpopstate”连接一个 AjaxEventBehavior。每当我执行 history.pushState 时,我都有添加对象的代码,我的问题是我无法使用 onEvent 从 Java 端访问这些额外信息。

pushState 示例:

target.appendJavaScript("history.pushState({query: '" + 
searchResults.getQueryString() + "'}, null, window.location.pathname);");

事件行为:

this.getPage().add(new AjaxEventBehavior("onpopstate")
{     
     @Override
     protected void onEvent(AjaxRequestTarget target)
     {
         //code to get query defined in pushState
     }
});

updateAjaxAttributes 不是解决方案,因为它仅在页面呈现时调用。当调用 popstate 时,我需要发送这些额外的数据。

【问题讨论】:

    标签: java ajax wicket html5-history wicket-7


    【解决方案1】:

    updateAjaxAttributes 实际上可以帮助您。 AjaxRequestAttributes 还允许您指定动态额外属性(有关更多信息,请参阅here)。这些参数是在触发 AjaxEventBehavior 之前在客户端动态计算的,并作为请求参数发送。

    【讨论】:

    • 您好,谢谢您的提示。它让我走上了正轨!我现在按照您的建议使用 getDynamicExtraParameters 。我面临的唯一问题是添加额外参数时,在我的事件中检索正确信息的时间太早了。有没有办法将执行延迟到以后?我传递给 getDynamicExtraParameters 的当前值是“return {'query' : attrs.event.originalEvent.state.query}”。
    • 我找到了解决问题的方法,我误用了 History API。感谢您的精彩回答!
    猜你喜欢
    • 2012-10-07
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    相关资源
    最近更新 更多