Reputation: 446
I'm developing with JSF & Primefaces and using the accordionPanel component in one of my current projects. This is a snippet code regarding to how I'm using it:
<p:accordionPanel id="historic" dynamic="true"
styleClass="noborder"
activeIndex="-1">
<p:tab id="tab1" title="Historic 1" >
<ui:include src="historic1.xhtml"/>
</p:tab>
<p:tab id="tab2" title="Historic 2">
<ui:include src="historic2.xhtml"/>
</p:tab>
<p:tab id="tab3" title="Historic 3">
<ui:include src="historic3.xhtml"/>
</p:tab>
<p:tab id="tab4" title="Historic 4">
<ui:include src="historic4.xhtml" />
</p:tab>
</p:accordionPanel>
All the tabs contain basically the same code, a form with some data pointing to different datasets. As you guys can see, it's pretty simple and works properly except with the last tab. It's never shown, whatever it contains. I mean, if, instead the code above, I put this other:
<p:accordionPanel id="historic" dynamic="true"
styleClass="noborder"
activeIndex="-1">
<p:tab id="tab1" title="Historic 1" >
<ui:include src="historic1.xhtml"/>
</p:tab>
<p:tab id="tab2" title="Historic 2">
<ui:include src="historic2.xhtml"/>
</p:tab>
<p:tab id="tab3" title="Historic 3">
<ui:include src="historic3.xhtml"/>
</p:tab>
<p:tab id="tab4" title="Historic 4">
<ui:include src="historic4.xhtml" />
</p:tab>
<p:tab id="tab5" title="Historic 5">
Some plain test text.
</p:tab>
</p:accordionPanel>
then the tab4 is now shown, but the tab5 isn't. I'm currently using this last code, but it's a bit ugly, because of the empty tab. Has any of you faced the same or similar problem and can help me? I'd appreciate it.
Upvotes: 2
Views: 536
Reputation: 446
The accordionPanel index is a zero-based one. This is, 0 for the first tab, 1 for the second one, and so on. That is why a tried to use "-1" as an index, because I didn't want any tab to be opened by default. But this value (-1) produces a malfunction in the accordionPanel: the last tab does not open properly. So if -1 doesn't work and 0 is the value for the first tab, what about a value "over" the last one. I mean, if we have 4 tabs (indexes from 0 to 3), let's try with 4... and it works. So simple. I hope this can be helpful for anyone who find themselves in the same problem. Anyway, thank @Aksel Willgert, you gave me the clue.
Upvotes: 0
Reputation: 11537
From the primefaces vdl: http://www.primefaces.org/docs/vdl/3.4/primefaces-p/accordionPanel.html
activeIndex
Index of the active tab or a comma separated string of indexes when multiple mode is on. Default is zero.
There might be reasons you set this to -1, the example you provided works in primefaces 3.4.2 if you set it to 0 or a positive number
Upvotes: 2