Vaadin 7 fire custom events between components

前端 未结 3 461
有刺的猬
有刺的猬 2021-01-21 03:43

I want to create custom events and fire them in some part of the view such that some other part of the view is updated/removed/refreshed.

I have tried by extending the C

3条回答
  •  误落风尘
    2021-01-21 04:23

    You can use EventRouter. But I do not use it.

    Or You can use ObjectProperty.

    This object can firing event when value is changed. For example:

    public class MyApplication extends UI{
      private ObjectProperty myState= new ObjectProperty(new MyState());
    
      public ObjectProperty getMyState(){return myState;}
    
    }
    
    
    public class MyComponent1 extends VerticalLayout{
    
      public MyComponent1(){
    
      //create UI
      ....
    
      updateData();
    
      Property.ValueChangeListener updateListener = new Property.ValueChangeListener() {
                        @Override
                        public void valueChange(Property.ValueChangeEvent event) {
                           updateData();
                        }
                    };
      MyApplication.getCurrent().getDispatcher().addValueChangeListener(updateListener);
    
    
      }
    
    private void updateData(){
      MyState myState = MyApplication.getCurrent().getMyState().getValue();
    
      //update this component with myState
    
    }
    }
    
     public class MyComponent2 extends VerticalLayout{/*Similarly with Component1*/}
    

提交回复
热议问题