fireEvent from within another event?

Events I’m firing are not being fired or maybe not received. Not sure which.

I have a checkbox with a valueChangeLsitener

checkbox.addValueChangeListener(e -> save(practice, personId, e));

In the save method, I’m firing an event as follows:

private void save(Practice practice, String personId, AbstractField.ComponentValueChangeEvent<Checkbox, Boolean> event) {
practice.updateAttendance(personId, event.getValue());
service.save(practice); //shown for context
fireEvent(new PracticeSurvey.UpdateEvent(this));
}

The event is defined as:

public static class UpdateEvent extends ComponentEvent<PracticeSurvey> {
    UpdateEvent(PracticeSurvey source) {
        super(source, false);
    }
}

The listener is defined in another class which extends VerticalLayout:

this.addListener(PracticeSurvey.UpdateEvent.class, e -> updateStatusColor(panel));

The method, updateStatusColor, never gets called. I’ve debugged all the way thru the firing of the event and I’ve even confirmed the event is registered with the EventBus (appears to be from what I can discern from the values at hand).

In a nutshell, I have a layout with checkboxes that saves to a DB when clicked and then I’m triggering an event to check if all, some, or none of the boxes are checked and updating the accordion summary’s color.

I don’t see why I wouldn’t be able to fire an event while inside another event. Can’t find anything in the api docs that mentions it either way.
image.png
image.png

https://cookbook.vaadin.com/ui-eventbus are you looking for

this.fireEvent is “scoped” to the component it was fired from, not it’s parent or siblings - for those you need a “higher-up” source like the UI as top most component

Welp, apparently EventBus is component specific, which I assumed was not the case. DOH!

Adding:

public <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType, ComponentEventListener<T> listener) {
        return getEventBus().addListener(eventType, listener);
    }

to my PracticeSurvey and calling it:

PracticeSurvey survey = new PracticeSurvey(practice, practiceService, personId);
            survey.addListener(PracticeSurvey.UpdateEvent.class, e -> updateStatusColor(panel));

makes it work as I wanted. Still learning Vaadin Flow, but lovin it!

Thanks knoobie for the link. Will be reading it fully.