jmix
jmix copied to clipboard
UiEventListeners is typed ApplicationEvent and not a specific event type
Environment
Jmix version: 2.2.999-SNAPSHOT
Bug Description
Look at the following methods:
-
io.jmix.flowui.component.main.JmixUserIndicator#onApplicationEvent
-
io.jmix.notificationsflowui.component.notificationsindicator.NotificationsIndicator#onApplicationEvent
-
io.jmix.quartzflowui.view.jobs.JobModelListView#onApplicationEvent
All of them are typed on ApplicationEvent
. Thus, when a UI event is published, all three listeners are triggered. In the implementation of these listeners, a type check occurs, and if the current event type matches the listener, then the listener processes it.
If you change method signatures to a specific event type, you will get an error.
E.g.:
protected void onApplicationEvent(VaadinSessionNotificationEvent event) {
// some code
}
protected void onApplicationEvent(UiUserSubstitutionsChangedEvent event) {
// some code
}
When publishing any UI event, filtering occurs by event type, but it is not correct. See:
-
io.jmix.flowui.sys.event.UiEventsManager#filterComponentListeners
-
io.jmix.flowui.sys.event.UiEventsManager#supportsEvent
According to this logic, any event time is suitable. Therefore, when publishing an event in the following method io.jmix.flowui.sys.event.UiEventsManager#invokeListener
a java.lang.ClassCastException
error occurs.
We need to add proper filtering and change the signature of the listener methods so that they are parameterized by a specific event type.
Sample Project
- Apply the following patch to the master branch: UiEventsManager_with_ApplicationEvent.patch
- Publish modules
flowui
,quartz-flowui
,notifications-flowui
to maven local - Open the following project: ui-event-listeners-bug.zip
- Log in as
admin/admin
- Open
UserListView
- Add or remove
UserSubstitutions
for admin to trigger UiUserSubstitutionsChangedEvent - An error occurs