我正在使用带有历史记录API的Wicket7.x。我目前正在尝试为“ onpopstate”连接一个AjaxEventBehavior。我有在我执行history.pushState时添加对象的代码,我的问题是我无法使用onEvent从Java端访问此额外信息。
示例pushState:
target.appendJavaScript("history.pushState({query: '" +
searchResults.getQueryString() + "'}, null, window.location.pathname);");
EventBehavior:
this.getPage().add(new AjaxEventBehavior("onpopstate")
{
@Override
protected void onEvent(AjaxRequestTarget target)
{
//code to get query defined in pushState
}
});
updateAjaxAttributes不是解决方案,因为仅在呈现页面时才调用它。调用popstate时,我需要发送这些额外的数据。
updateAjaxAttributes实际上可以为您提供帮助。 AjaxRequestAttributes使您还可以指定动态额外属性(有关更多信息,请参见here)。这些参数是在AjaxEventBehavior触发之前在客户端动态计算的,并作为请求参数发送。