Time for action – tracking an active tab dynamically
Let us see how we can maintain the activeIndex
value of the tab that the user clicked, so that we can display the user-clicked tab as an active tab, by performing the following steps:
- To dynamically keep track of the active tab, we can create a template containing the TabMenu definition with
activeIndex
bound to a dynamic property:<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <p:tabMenu activeIndex="#{activeIndex}"> <p:menuitem value="Home" url="home.jsf" icon="ui-icon-home"/> <p:menuitem value="Post Buzz" outcome="tabMenu" icon="ui-icon-document"/> <p:menuitem value="Search" action="#{menuController.showSearchPage}" ajax="false" icon="ui...