1

I want to know how to get all the tabs in the JSF layer without going into the ontabChange method.

I have a system with dynamic tabs. Depending on the values users keyed in, different tabs will be rendered. After saving, the user needs to be directed to the "Account" tab, however with all the tab renderings, the index for "Account" may have changed.

If user do a tab change then it's fine, because I can get all the children for the tab and navigate to whichever index "Account" is.

But the problem is, how do I populate the tab and the children if the user did not call the ontabchange method, meaning that the user did not do any navigate to other tabs and straight away save the information.

            <p:tabView id="tabView"
                activeIndex="#{userBacking.tabInt}">
                <p:ajax event="tabChange" immediate="true" update=":form:message"
                    listener="#{userBacking.onTabChange}" />

                <p:tab id="tab1" title="Personal Information">
                    // Items for tab 1
                </p:tab>

                <p:tab id="tab2" rendered="#{userBacking.renderedTab2}
                    title="Education">
                    // Items for tab 2
                </p:tab>

                <p:tab id="tab3" rendered="#{userBacking.renderedTab3}"
                    title="Qualifications">
                    // Items for tab 3
                </p:tab>

                <p:tab id="tab4" rendered="#{userBacking.renderedTab4}"
                    title="Contact Information">
                    // Items for tab 4
                </p:tab>

                <p:tab id="tab5" title="Account">
                    // Items for tab 5
                </p:tab>
            </p:tabView>

Without the user calling the ontabchange, I want to get all the tabs available and navigate to the "Account" tab.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • You can possibly [bind the p:tabView to a requestScoped bean](https://stackoverflow.com/questions/14911158/how-does-the-binding-attribute-work-in-jsf-when-and-how-should-it-be-used) and query the tab indexes from there. – Selaron Nov 08 '19 at 07:25
  • If the code above is really your [mcve], I'd say it should be easy to solve by counting how many tabs are visible (I'd personally use a map with visibility instead of separate methods, so `#{userBacking.visible['tab2']` etc. Then the index of the account tab is always the number of additional visible tabs +1 No need for binding etc... – Kukeltje Nov 08 '19 at 09:26
  • Hi @Selaron, the bean I am using is ConversationScoped – Nik Mohamad Lokman Nov 25 '19 at 05:40
  • Can't you simply count somewhere how many of the `userBacking.renderedTab2` to `userBacking.renderedTab4` properties are `true`? And what about kukeltjes suggestion? – Selaron Nov 25 '19 at 07:21

0 Answers0