I have a block level element, a container, that should be hidden when all its child Wicket elements (buttons) are hidden. In other words, if any child button is visible, the container should be visible.
Earlier one of the buttons was always visible if any buttons were, so I used that button to control the visibility of a <wicket:enclosure>
, handling all of this purely on HTML side.
Now, the specs have changed so that the buttons can be hidden/visible independently, so a simple enclosure won't work anymore (I think).
I got it working with something like this:
HTML:
<wicket:container wicket:id="downloadButtons">
<wicket:message key="download.foo.bar"/>:
<input type="button" wicket:id="excelDownloadButton" wicket:message="value:download.excel"/>
<input type="button" wicket:id="textDownloadButton" wicket:message="value:download.text"/>
<!-- etc ... -->
</wicket:container>
Java:
WebMarkupContainer container = new WebMarkupContainer("downloadButtons");
// ... add buttons to container ...
boolean showContainer = false;
Iterator<? extends Component> it = container.iterator();
while (it.hasNext()) {
if (it.next().isVisible()) {
showContainer = true;
break;
}
}
addOrReplace(container.setVisible(showContainer));
But the Java side is now kind of verbose and ugly, and I was thinking there's probably be a cleaner way to do the same thing. Is there? Can you somehow "automatically" hide a container (with all its additional markup) when none of its child components are visible?
(Wicket 1.4, if it matters.)