Thursday, November 25, 2010

In my last post I looked at some quirks of using the ICEfacesPanelTabSet with Metawidget. Specifically, because PanelTabSet stores the selectedIndex of the current tab inside the component, the component cannot succesfully be destroyed and recreated.

To work around this we looked at using Metawidget's COMPONENT_ATTRIBUTE_NOT_RECREATABLE to preserve the selectedIndex at the expense of some dynamicism. We further looked at using JSF's binding attribute to try and claw back some of that dynamicism.

However, a different approach entirely would be to stop PanelTabSet storing selectedIndex internally! It turns out ICEfaces provides an API for this. The only question is where else to store selectedIndex, but keeping it inside the current request seems to work nicely. So:

Forget all about COMPONENT_ATTRIBUTE_NOT_RECREATABLE and the binding attribute (and related mMetawidget inside the managed bean)

So now you get fully dynamic tabs at the same time as tab switching working! This technique only applies in those cases where the UIComponent thoughtfully exposes such an API, but in such cases it's very useful.