Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabView/AccordionPanel: Introduce TabEvent#index #11553

Open
melloware opened this issue Mar 2, 2024 · 2 comments
Open

TabView/AccordionPanel: Introduce TabEvent#index #11553

melloware opened this issue Mar 2, 2024 · 2 comments
Assignees
Labels
enhancement Additional functionality to current component workaround A workaround has been provided
Milestone

Comments

@melloware
Copy link
Member

melloware commented Mar 2, 2024

Discussed in https://github.com/orgs/primefaces/discussions/1320

Originally posted by DaBe1812 February 28, 2024
I have a dynamic TabView getting it's content from a List<>.
Opening new tabs works just fine, switching between those tabs updates the ActiveIndex correctly.
Let's pretend I have 6 open tabs, so the last index ist 5. When I close tab no 2 then the last index stays 5 switching the tabs skips TabIndex 1. When I want to clear my List by closing tabs this is a problem becase the indexes in the list differ from the indexes of the tabs.
Is there a way to update the tab indexes or a workaround for this issue?

Workaround from Raptser:

public void onTabClose(TabCloseEvent<?> event) {
      TabView tv = (TabView) event.getComponent();
      int activeIndex = Integer.parseInt(event.getFacesContext().getExternalContext().getRequestParameterMap().get(tv.getClientId() + "_tabindex"));

      FacesMessage msg = new FacesMessage("Closed", "Closed Tab. Active Tab " + activeIndex);
      FacesContext.getCurrentInstance().addMessage(null, msg);
}
@melloware melloware changed the title TabView ActiveIndex isn't as expected TabView: ActiveIndex isn't as expected Mar 2, 2024
@melloware melloware transferred this issue from primefaces/community Mar 2, 2024
@melloware melloware added the 🐞 defect Bug...Something isn't working label Mar 2, 2024
@melloware melloware added this to the 15.0.0 milestone Mar 2, 2024
@melloware melloware added the workaround A workaround has been provided label Mar 2, 2024
@melloware
Copy link
Member Author

melloware commented Mar 2, 2024

it looks like AccordionPanel and TabView share similar code around how it handles this TabClose event so the bug is probably in both.

String tabClientId = params.get(clientId + "_closeTab");
TabCloseEvent closeEvent = new TabCloseEvent(this, behaviorEvent.getBehavior(), findTab(tabClientId));

if (repeating) {
    int tabindex = Integer.parseInt(params.get(clientId + "_tabindex"));
    setIndex(tabindex);
    closeEvent.setData(getIndexData());
    closeEvent.setTab(getDynamicTab());
}

closeEvent.setPhaseId(behaviorEvent.getPhaseId());

super.queueEvent(closeEvent);

if (repeating) {
    setIndex(-1);
}

@jepsar
Copy link
Member

jepsar commented Mar 2, 2024

Index is not great to indicate a tab when the are dynamic. Using an ID would be better.

@Rapster Rapster changed the title TabView: ActiveIndex isn't as expected TabView: Introduce TabEvent#index Mar 3, 2024
@Rapster Rapster added enhancement Additional functionality to current component and removed 🐞 defect Bug...Something isn't working labels Mar 3, 2024
Rapster added a commit to Rapster/primefaces that referenced this issue Mar 3, 2024
Rapster added a commit to Rapster/primefaces that referenced this issue Mar 3, 2024
@Rapster Rapster changed the title TabView: Introduce TabEvent#index TabView/AccordionPanel: Introduce TabEvent#index Mar 3, 2024
@jepsar jepsar linked a pull request Mar 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additional functionality to current component workaround A workaround has been provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants