Closing inactive tabs in rich tabPanel by user action
atulkc Apr 24, 2009 12:24 PMHi All,
In our application we have a tabPanel with multiple tabs. All the tabs but one can be closed by clicking on 'x' in the tab header. Below given is the code snippet:
<rich:tabPanel id="tabs" selectedTab="#{viewManager.selectedTab}" switchType="ajax" > <!-- First tab that cannot be closed --> <rich:tab name="one" rendered="true"> <f:facet name="label"> <h:panelGrid columns="1" cellpadding="2" columnClasses="rich-tab-header"> <h:outputText value="One" /> </h:panelGrid> </f:facet> <h:outputText value="Contents of First tab"/> </rich:tab> <!-- Secont tab that can be closed --> <rich:tab name="Two" rendered="#{viewManager.secondTabRendered}"> <f:facet name="label"> <h:panelGrid columns="2" cellpadding="2" columnClasses="rich-tab-header"> <h:outputText value="Two" /> <a4j:commandButton value="x" reRender="tabs" action="#{viewManager.secondTabRendered('0')}"> </a4j:commandButton> </h:panelGrid> </f:facet> <h:outputText value="Contents of second tab"/> </rich:tab> ... ... ... <!-- multiple such tabs that can be closed --> </rich:tabPanel>
"viewManager" is a session scoped backing bean that has appropriate getter/setter methods to achieve hiding/rendering of different tabs.
The intention here that when user clicks 'x' in the tab header then the tab should be closed and user returns to the first tab. Well, this is perfectly achieved using this code when the tab is active. When the tab is active clicking on 'x' actually closes the active tab and returns the user to first tab.
Our intention is also to allow user to close the tabs even if the tab is inactive, meaning when the second tab is inactive (user is currently in first tab) then user should be able to click on 'x' of second tab header and close that tab without ever having to go to that tab (similar to firefox tab behavior). However, with the above code we are not able to achieve that. Clicking on 'x' of the inactive tab is resulting in making the inactive tab active. So clicking on 'x' of second tab actually takes user to second tab in place of closing it. Is there a way by which we can make rich faces not interpret this action as tab change but tab close?
Any pointers/help is appreciated.
Regards,
Atul