如何在组件的 Wicket 的 onBeforeRender() 方法中获取 AjaxRequestTarget? [英] How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

查看:27
本文介绍了如何在组件的 Wicket 的 onBeforeRender() 方法中获取 AjaxRequestTarget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发各种 Wicket 面板重绘的 Ajax 事件.一些面板在它们的 onBeforeRender() 方法中有自己的额外计算.如果有错误,我想显示给用户.但是我无法将 FeedbackPanel 添加到 AjaxRequestTarget 中,因为我无法再在正在重绘的面板内访问它.

I have an Ajax event that triggers the redraw of various Wicket panels. Some panels have additional calculations of their own inside their onBeforeRender() method. If there is an error, I want to display it to the user. But I can't add the FeedbackPanel to the AjaxRequestTarget because I don't have access to it anymore inside the panel that is being redrawn.

有没有办法在 Wicket 组件的 onBeforeRender() 中获取 AjaxRequestTarget?一旦第一个组件已经处于 onBeforeRender() 状态,甚至可以向 Ajax 目标添加其他组件吗?

Is there a way to get the AjaxRequestTarget inside onBeforeRender() of a Wicket component? Is it even possible to add additional components to the Ajax target once the first ones are already in onBeforeRender() state?

如果只有需要重绘的面板才能决定是否有错误,有没有更好的方法将 FeedbackPanel 添加到 Ajax 目标中?

Is there a better way to add the FeedbackPanel to the Ajax target if only the panels that need to be redrawn can decide if there is an error or not?

推荐答案

获取 AjaxTarget 是这样完成的:

Getting the AjaxTarget is done like this:

AjaxRequestTarget target = requestCycle.find(AjaxRequestTarget.class);

不幸的是,正如预期的那样,一旦我处于渲染阶段,我就无法向目标添加组件.但是 Wicket 提供了接口 ITargetRespondListener 使用方法 onTargetRespond(AjaxRequestTarget target).在这里,我可以向目标添加任何我想要的东西.

Unfortunately, like expected, I can't add components to the target once I'm in the rendering phase. But Wicket provides the interface ITargetRespondListener with the method onTargetRespond(AjaxRequestTarget target). Here I can add anything I want to the target.

这篇关于如何在组件的 Wicket 的 onBeforeRender() 方法中获取 AjaxRequestTarget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆