0

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

示例推送状态:

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 时,我需要发送这些额外的数据。

4

1 回答 1

1

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

于 2017-10-03T19:53:40.090 回答