0

Please refer to my previous question.

I need to be able to identify the entity associated with each tab (or row) in a p:accordionPanel. E.g. if the rows correspond to entities whose IDs are 1, 2, 3, when I click on each tab, I want to trigger an event to be processed by the controller that uses the ID of that tab. IOW, I need a reference pointer between each tab and the controller.

The ID atribute, as can be seen from my previous post, did not work. How can I establish identity reference between each tab in the view and the controller?

Community
  • 1
  • 1
amphibient
  • 29,770
  • 54
  • 146
  • 240

1 Answers1

2

You can try to use the activeIndex attribute of the accordionPanel which is the index of the active tab.

<p:accordionPanel activeIndex="#{playgroundController.activeIndex}">
    <p:ajax event="tabChange" listener="#{playgroundController.onTabChange()}" />
    <p:tab title="Godfather Part I">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText
                value="The story begins as Don Vito Corleone..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part II">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText value="Francis Ford Coppola's legendary..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part III">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText value="After a break of more than 15 years..." />
        </h:panelGrid>
    </p:tab>
</p:accordionPanel>

Bean:

private String activeIndex = "";


public void onTabChange() {
    logger.debug("onTabChange : activeIndex : {}  ", activeIndex);
}

While clicking on one of the tabs it prints:

09:38:55,822 DEBUG [PlaygroundController] onTabChange : activeIndex : 0  
09:38:56,625 DEBUG [PlaygroundController] onTabChange : activeIndex : 1  
09:38:57,426 DEBUG [PlaygroundController] onTabChange : activeIndex : 2  
Emil Kaminski
  • 1,886
  • 2
  • 16
  • 26
  • but `activeIndex` is a bit dodgy because it is like an externally assigned counter and not inherent to the entity – amphibient Dec 11 '14 at 15:49