How to find if a tab is already open in Vaadin and it is activated rather than creating a new one

In Vaadin, when you have a TabSheet tab and some tabs are already open, you do not want the same tab containing the same content to be opened many times. How to check that a tab is already open and set it as selected?

+4
source share
4 answers

The Vaadin TabSheet is checked by default if the component has already been changed by comparing the hash of the component.

This means that you must implement the hashCode () method in the component that you want to add to the TabSheet.

+3
source

Using an iterator in a tab component and comparing with a name.

Iterator<Component> i = tabSheet.getComponentIterator(); while (i.hasNext()) { Component c = (Component) i.next(); Tab tab = tabSheet.getTab(c); if (name.equals(tab.getCaption())) { tabSheet.setSelectedTab(c); return; } } 
+3
source

In the new Vaadin, this can be solved as follows:

 Component component = //... for (Component c : tabSheet) { if (c.equals(component)) { // duplicate... } } 

But as @CRH mentioned earlier, you have to make sure equal() and hashCode() correct.

0
source

In my case, this can be done as follows:

 Component cmp = /*you component with a description*/; for (Component c : tabSheet) { if (c.getDescription().equals(cmp.getDescription())) { System.out.println("Equals Equals"); return; } } 
0
source

All Articles