Events propagation and Handling in Vaadin 8

After reading a lot of docs, posts, tutorials I can’t find a solution.
I don’t understand event handling in Vaadin.

The case is :
I try to capture the event(ButtonClick) from a custom component include in another (main) component.
The first CustomComponent (which has to deal with the sent event) is a grid view, the second (the one which should send the event) is just a two buttons CustomComponent (bValid,bCancel).

What I understood (maybe I’m wrong) is the first class should implement listener to capture events.

I use Vaadin 8 and develop Server-Side only.

If someone have an example, a link, or anything that could help me it would be great !!


maybe this
Handling Events with Listeners
chapter in the Book of Vaadin will help?


I already read the doc twice but I can´t find :frowning:
this the reduce code :

public class GroupsConf extends VerticalLayout implements View, Button.ClickListener {


    private GroupesFacade groupesFacade;

    public GroupsConf() {
        hLayout = new HorizontalLayout();
        vLayoutGroup = new VerticalLayout();
        vLayoutUsers = new VerticalLayout();

        gridGroupes = new Grid<>();

 boutons = new BoutonCreerSupprimer();

        gridUsers = new Grid<>();

    public void enter(ViewChangeListener.ViewChangeEvent event) {
        List<Groupes> listGroupes = groupesFacade.findAll();
        gridGroupes.addItemClickListener((clicEvent) -> {

        gridUsers.addItemClickListener((clicEvent) -> {

        hLayout.addComponents(vLayoutGroup, vLayoutUsers);

        this.setComponentAlignment(hLayout, Alignment.TOP_CENTER);

    private void selectGroup(ItemClick<Groupes> clic) {
        if (clic.getMouseEventDetails().isDoubleClick()) {
            Window editGroupWindow = new Window();
            EditGroups editGroupComponent = new EditGroups();
        } else {
            List<Utilisateurs> listUsers = clic.getItem().getUtilisateurs();

    private void editUser(ItemClick clicEvent) {
        if (clicEvent.getMouseEventDetails().isDoubleClick()) {
            System.out.println(((Utilisateurs) clicEvent.getItem()).getIdentifiant());

    public void buttonClick(Button.ClickEvent event) {
        System.out.println("ca clic");

The Custom Component :

public class BoutonCreerSupprimer extends CustomComponent{

public BoutonCreerSupprimer() {
    hLayout = new HorizontalLayout();

    this.delete = new Button(VaadinIcons.TRASH);

    this.create = new Button(VaadinIcons.CHECK);

private void ok(Button.ClickEvent event){
    System.out.println("echo"); // ok "echo" is printed
    //event.getButton().click(); // SEVERE [com.vaadin.server.DefaultErrorHandler]

(default task-102) : com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.test.BoutonCreerSupprimer$$Lambda$488/1890208777 failed.
//this.fireEvent(event); // nothing printed from buttonClic
[/code]What I want is to capture the event (ButtonClick) in the containing component (GroupConf class)
I certainly miss something but what :smiley:

So I changed some things,

now the GroupConf class implement LayoutClickEvent With the fireEvent BoutonCrèerSupprimer class I can catch my event with event.getClickedComponent().getCaption() but it only work if I double click the button

Have you tried passing your object that implements Button.ClickListener to the Button instances instead of using Lambda expressions or method references?


Yes I have tried. May be I don’t understand how to manage events, I used to develop UI using AS3 and I thing the events are not propagating/handling the same way, for this time because I can’t find a solution I give up and will create new buttons directly in my main composant.
I read last night the part of the doc “Client-Server integration” , may be a solution for me should be using Connectors and rpc calls.
Read, read, coffee, read, re-coffee, test, test, tea, debug…
I remember why I stopped this profession 4 years ago XD XD XD XD
Thanks for your time.

RPC calls sound like overkill for your situation, it should all be perfectly doable from the server side. I’m not sure what is going wrong exactly, but it does sound like you’re attempting to do something in a peculiar way. One thing to note about events that they’re not automatically propagated anywhere - you have to add listeners to the components and deal with the events there or pass them on to some other method as plain old Java objects. That’s to say, there’s no built in event bus. A typical way of adding a listener in your case could be something like this:

public class GroupsConf extends VerticalLayout implements View, Button.ClickListener {
// ...
        boutons = new BoutonCreerSupprimer(this);
    public void buttonClick(Button.ClickEvent clickEvent) {"foo");
public class BoutonCreerSupprimer extends CustomComponent {
   public BoutonCreerSupprimer(Button.ClickListener listener) {
        Button button = new Button();
        button.addClickListener(listener); // note: you shouldn't remove listeners in Vaadin 8
// ...        


Thanks again Olli,
Effectively I thougth events were automatically propagated, I’m no more use (or use anymore) with this pattern… so READ AGAIN…:smiley:
Thanks a lot