Wicket enclosures and ajax : no no
17/09/2009 2 Comments
Okay, this will be my second post in English, so, don’t go too hard on me :)
Earlier today, I was working on a web application using Wicket as framework, and I’ve got bitten by something that I wanted to share.
More precisely, it’s about enclosures and ajax : I had a link inside a list item and I wanted to bind the visibility of the latter to of the former.
So, I went ahead and enclosed the list item in an enclosure specifying the link wicket id as a value for the child attribute :
<wicket:enclosure child="generateReport"> <li> <a href="#" wicket:id="generateReport">Generate report</a> </li> </wicket:enclosure>
And this worked just fine, until I’ve decided I wanted to change the link’s visibility using Ajax.
So, when generating a full web page response, Wicket is perfectly able to handle the enclosures. But when ajax is involved, Wicket simply can’t handle them because they have no corresponding element in the html page, and thus they can’t be updated later. The inner element’s (<a> in this case) visibility will be affected but that’s not the case for the enclosure whose visibility remains static (depending on whether it was visible or not when the page was generated).
Note: The Wicket’s wiki mentions this behavior :
Note: Changing the visibility of a child component in Ajax callback method will not affect the entire enclosure but just the child component itself. This is because only the child component is added to the AjaxRequestTarget.