How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

♀尐吖头ヾ 提交于 2019-12-04 13:04:02

问题


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.

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?

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?


回答1:


Getting the AjaxTarget is done like this:

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

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.



来源:https://stackoverflow.com/questions/19246892/how-to-get-the-ajaxrequesttarget-inside-wickets-onbeforerender-method-of-a-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!