Wick AjaxEventBehavior with History API

时间:2017-10-03 16:32:53

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

我正在使用Wicket 7.x和History API。我目前正在尝试为“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时发送这些额外的数据。

1 个答案:

答案 0 :(得分:1)

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

相关问题