Component Lifecycle Callbacks

    1. @Tag("div")
    2. public class ShoppingCartSummaryLabel extends Component {
    3. private final Consumer<EventObject> eventHandler = this::onCartSummaryUpdate;
    4. @Override
    5. protected void onAttach(AttachEvent attachEvent) {
    6. ShopEventBus eventBus = attachEvent.getSession().getAttribute(ShopEventBus.class);
    7. }
    8. @Override
    9. protected void onDetach(DetachEvent detachEvent) {
    10. ShopEventBus eventBus = detachEvent.getSession().getAttribute(ShopEventBus.class);
    11. // after detaching don't need any updates
    12. eventBus.unregister(eventHandler);
    13. }
    14. // update cart summary ...
    15. }
    16. }
    17. void register(Consumer<EventObject> eventHandler);
    18. void unregister(Consumer<EventObject> eventHandler);
    19. }