O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. 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}" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required