-1

I need to get the intex of an oppened tab. I'm using this ajax on the accordionPanel:

<p:ajax event="tabChange" listener="#{ambienteController.onAccordionTabChange}" />

And this is the bean:

public void onAccordionTabChange(final TabChangeEvent event) {
    AccordionPanel view = (AccordionPanel) event.getComponent();
    this.accordionTabIndex = view.getActiveIndex();
    System.out.println(this.accordionTabIndex);
}

The sysout is always printing 0 as the index of the current active tab, this is messing me up since i use that info to add files to specific tabs that reflect environments the user has, so all files end up on the first tab. Thanks in advance.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
GaboSampaio
  • 181
  • 1
  • 11
  • which version of Primefaces are you using? – Alex Dec 05 '19 at 18:13
  • I'm using version 5.2 – GaboSampaio Dec 05 '19 at 18:21
  • 1
    check if you can make use of `event.getTab()` ? – Alex Dec 05 '19 at 18:24
  • 1
    [mcve] please only thing that can help. Read http://idownvotedbecau.se/nomcve/ and orevent guessing and giving wrong suggestions – Kukeltje Dec 05 '19 at 18:27
  • Does this answer your question? [primefaces tabView activeIndex issue](https://stackoverflow.com/questions/5222819/primefaces-tabview-activeindex-issue) – Selaron Dec 05 '19 at 19:21
  • @Selaron: OP seems to be doing what is in the duplicate... Besides the issue being mentioned in the duplicate (which is an old broken link in google code) can you state why you think it is a duplicate? (Not saying you are wrong, I just might miss something) – Kukeltje Dec 05 '19 at 21:26
  • @GaboSampaio: Step 1: ALWAYS try a newer (latest) version. Is easy to do with a [mcve] – Kukeltje Dec 05 '19 at 21:29
  • @Kukeltje the accepted answer suggests to use `getIndex()` instead of `getActiveIndex()`. While on mobile I couldn't check how this is different. Now looking at the source the `index` property (not `activeIndex`) is set for dynamic tabs only. Beside the hint to use `getIndex()` there are other upvoted answers suggestings things that look plausible and possibly helpful. As there is not enough detail to answer this question I considered it best option to throw a CV packaged with these guesses that may or may not help. – Selaron Dec 06 '19 at 08:04
  • @Selaron: Thanks for the clarification. I indeed missed that smal (yet most likely important) difference. – Kukeltje Dec 06 '19 at 08:39
  • I would suggest using ariaLabel attribute to get the active tab via JQuery :) – BugsForBreakfast Dec 06 '19 at 15:56

1 Answers1

0

Try declaring a String index on your controller and setting on your accordionPanel component as on activeIndex="#{ambienteController.index}".

bryan
  • 83
  • 3
  • 9
  • The problem persisted, it seems like there is something wrong with the view.getActiveIndex for some reason it's always returning 0. – GaboSampaio Dec 05 '19 at 18:06