wicket:如何在 AjaxLazyLoadPanel 之后更新组件?
我有一个页面,其中有一个状态文本标签和一个执行一些数据库查询的面板。由于查询可能需要一些时间,所以我使用它加载它
add(new AjaxLazyLoadPanel("resultPanel")
{
@Override
public Component getLazyLoadComponent(String id) {
return new SearchResultPanel(id);
}
};
,效果非常好。
我的问题是如何更新 resultPanel 之外的状态标签,以显示搜索结果的数量?
我正在考虑 addComonent(target) 的思路,但我没有目标?我偏离轨道了吗?
I have a page that has a status text label and a panel doing some DB query. since the query can take some time I am loading it using
add(new AjaxLazyLoadPanel("resultPanel")
{
@Override
public Component getLazyLoadComponent(String id) {
return new SearchResultPanel(id);
}
};
which works very well.
My question is how to update the status label which is outside of the resultPanel, to show the number of search results?
I was thinking along the lines of addComonent(target) but I don't have a target? am i off the track?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那么 SearchResultPanel 可能看起来像这样:
现在,当它加载时,它应该抛出该 javascript。之前在 stackoverflow 上回答的另一种方法(尽管我不喜欢它)是使用 AjaxSelfUpdatingTimerBehavior,除非 javascript 应该运行一次我不喜欢的次数,但在我看来它仍然不太优雅。
在这里寻找他们的答案:Wicket:自动重新加载 AjaxLazyLoadPanel
Well the SearchResultPanel might look like this:
Now when it is loaded it should throw out that javascript. Another way answered on stackoverflow previously (though I do not like it) is to use an AjaxSelfUpdatingTimerBehavior, which unless the javascript should be ran more then once I do not like, and still it is less elegant in my opinion.
Look here for their answer: Wicket: reload AjaxLazyLoadPanel automatically
如果存在活动请求周期,您始终可以使用 RequestCycle.get().getRequestTarget() 获取当前请求目标,因此理论上您可以从延迟加载的组件构造函数中执行此操作,检查它是否是 Ajax 目标,如果是,则添加组件。
另一种解决方案是查看 AjaxLazyLoadPanel 的源代码并基于它创建您自己的组件。 (这非常简单,但是如果您查看代码,您就会发现,您无法使其公开请求目标。这不是一件非常面向对象的事情,但由于所有重要的功能都包含在构造函数中,你别无选择。
我会避免篡改Javascript,除非真的没有其他办法。
You can always obtain the current request target using
RequestCycle.get().getRequestTarget()
, provided that there is an active request cycle, so in theory you could do that from your lazy-loaded component constructor, check if it is an Ajax target, and add the component if it is.Another solution is to look at the source code of
AjaxLazyLoadPanel
and create your own component based on it. (It's really simple but as you can see if you look at the code, there's no way you can make it expose the request target. This isn't a very OO thing to do, but as all the important functionality is wrapped in the constructor, you have very little choice..I would avoid having to tamper with Javascript, unless there's really no other way.
偶然看到这篇文章,我也有一些补充。
AjaxLazyLoadPanel 现在有一个名为 onComponentLoaded(Component, AjaxRequestTarget) 的可重写方法,它也可以解决您的问题。
Happened to come across this post and I have something to add as well.
The AjaxLazyLoadPanel now has an overridable method called onComponentLoaded(Component, AjaxRequestTarget) which could also solve your problem.