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
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*/}