Wicket Label not updated / remains invisible

冷暖自知 提交于 2019-11-30 09:58:20

When playing with a component's visibility through Ajax, it's necessary to use setOutputMarkupPlaceholderTag(true), in addition to setOutputMarkupId(true). Notice that setOutputMarkupPlaceholderTag(true) will automatically imply setOutputMarkupId(true).

The reasons to do so are that when a component gets refreshed through Ajax (adding it to the AjaxRequestTarget), Wicket returns the refreshed markup in the Ajax response, so that it will be replaced via JS-DOM API through the Ajax callback method. So, for the JS function that will replace the received markup to work, it's necessary to have a reference to the DOM node to replace (an HTML id attribute). That's why setOutputMarkupId(true) is needed.

When changing visibility, if the component is non-visible, Wicket will not generate any markup for the component, which is great, but has a drawback. If an invisible component turns out to be visible in a following ajax request, its markup will be effectively returned in the Ajax response. But, since the component was not visible, it will not even exist in the original markup, and it will be impossible to replace the DOM node at callback time. That's where the setOutputMarkupPlaceholderTag(true) method enters into action, wrapping the maybe-not-visible component in a placeholder tag (i.e. a <div>), that will always be rendered with the proper HTML id attribute.

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