0
VerticalLayout group = new VerticalLayout(new TextField("field-01"),
                                          new TextField("field-02"));
group.addListener((Component.Listener) e ->  System.out.println("catch event:$e"));

i see only attach events, but i want to catch any events of the inner components. For example hide some component depends of the state another.

petey
  • 16,914
  • 6
  • 65
  • 97
Sotona
  • 158
  • 11
  • I'd advise against using a single event handler which probably has a huge if or switch statement to figure out who did what. I'd add individual handlers for the components and update the _dependencies_ accordingly. If your scenario is relatively complex, perhaps you could use a [mediator](https://en.wikipedia.org/wiki/Mediator_pattern) or [state](https://en.wikipedia.org/wiki/State_pattern) pattern to keep track of the changes to be done when certain events are triggered. – Morfic Mar 31 '17 at 10:37
  • thanks. its a good idea. I think it is possible to implement a some common event router, which send event to a desired component handler. no if|switch, only annotations )) – Sotona Apr 06 '17 at 17:13
  • If you do not want to add listeners manually to each field you are adding the layout, you could loop through components and cast to HasValue (which is the common interface for fields) and call addValueChangeListener. I do not really understand your requirement, so you may describe your use case in detail. – Steffen Harbich Jun 23 '17 at 11:40

0 Answers0