Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Spring Boot @EventListener

Mikhail Emelchenkov
3 years ago Jan 26, 2019 3:47pm

With Vaadin 8 I used Spring Boot ApplicationEventPublisher and @EventListener annotation in views @UIScope @SpringView. Moving to Vaadin 12 now I use @Route "MainView extends AppLayout implements RouterLayout" and sub-route "@Route(value="admin", layout=MainView.class)". So, the only way to make @EventListener work is making this sub-route a Spring component. If I set annotation @SpringComponent, it become persistent, which I don't like. I like its approach when switching tabs in AppLayout first creates, then destroys sub-route. Changing sub-route's scope to @Scope("request") creates a new instance of sub-route at each call of @EventListener method. What's the best way to implement proper event handling from server-side? I like Spring's ApplicationEventPublisher but don't see a way how to use it in sub-route. For main view I just declared it as @SpringComponent @UIScope and @EventListener works as expected. This question is also related to https://vaadin.com/forum/thread/17487924/push-when-to-use.

Last updated on Jan, 26th 2019
Brad Harrison
10 months ago Apr 26, 2021 9:53pm