Broadcaster and TabSheet

Vaadin 23 here if it does matter…
I have a View with a single grid and a broadcaster. Works well, e.g. if I delete an entry it gets broadcasted as it should and shows a notification.

Now I have created a TabSheet containing two sheets consisting of that view by calling the views constructor, just different data within the grid by a variable in that constructor.

Deleting still works, but I get the Notification now twice… I think, it’s because I have now 2 broadcasters but from same ui (the TabSheet) .

How can I avoid such within a TabSheet? Any hints?

You can probably apply the notification only if the “view” is visible or attached ( I don’t remember how the tabsheet is working).

yes, but… :smile:
I think it comes from the broadcaster registering twice.
TabSheet has a route, the tabbed views don’t have. The first tabbed view is shown by default. The second one loads when chosen and registers the broadcaster again…
Somehow a bit confusing :smile:

How do you register/unregister the broadcaster?

as usual
Within the “grid views” onAttach and onDetach methods.

as the same “grid view” gets tabbed twice of course there are two similar “onAttach” methods called…

It’s working in general, only it’s IMHO not "clean :slightly_smiling_face:

https://tenor.com/view/only-one-there-can-be-only-one-highlander-gif-12213479

I’m not sure if I misunderstood you here, but you have a view / route and and later instantiate it yourself as simple component to be added as tabsheet’s content or are you using the full fledged version of a router based tabsheet from the cookbook? The first one is prown to have errors. The second should work correctly

Good morning :slightly_smiling_face:

Well - first there was a full-fledged view containing 2 grids side by side showing 2 different data sets for 2 different locations. It included the broadcasting

This view was stripped down to be more generic, one grid only. Route annotation was removed.

A new view with route annotation was buildt. It implements the tabsheet https://vaadin.com/docs/v23/components/tabs#tab-sheet

Mainly it contains
view1 = new StrippedView(Services, Location 1)
view2= new StrippedView(Services, Location 2)

tabSheet.add(“one”, view1)
tabSheet.add(“two”, view2)

Therefore the broadcasters are now registered twice as they are still available in the StrippedView. And that leads to this strange behaviour.

I guess I need to rethink this construct and perhaps follow the cookbook example. The above approach works well in all other situations but not with broadcaster involved.

:thinking: sounds like your broadcaster should check if the target is visible or something similar… because once both tabs were selected they stay in memory and are only visible removed on the client

The tabsheet doesn’t attach/detach the content of each tab. It doesn’t change the visibility but set enable to true/false.
So you could check view.isEnabled() (if it inherits HasEnabled) or view.getElement().isEnabled().
I think that should be a valid usecase and you can create a ticket about it.
You can also create your own Tabsheet component that remove the content from the tabsheet (and call attach/detach listener).

Thanks for looking into it… so it’s disabled and not invisible :see_no_evil:

That’s the exact code: flow-components/vaadin-tabs-flow-parent/vaadin-tabs-flow/src/main/java/com/vaadin/flow/component/tabs/TabSheet.java at main · vaadin/flow-components · GitHub

Thanks, you two
Will have a look at this soon, right now it isn’t at the top of our priority list :slightly_smiling_face: probably next week!