I’m currently developing a ZK application, but couldn’t find a way to listen for all SelectEvent
s fired from all components below one specific (which is the only one existing at the start, and then gets descendants with every selection taking place in it or a descendant).
The hierarchy below this component will change with every SelectEvent
, and I need to check conditions each time this happens.
The only things I can think of are
- define a function which does the condition check i need and additionally
- adds to all decendants (which don’t have one) event listeners, which call this function
- register an event listener on the page which does the condition check. fires more often than necessary, but better than not at all.
both don’t feel right, and the latter isn’t safe if multiple root components are there (as each of these has it’s own set of descendants)
Is there some way I have overlooked?
PS: this is the ZK version of this question.
Some code. The ExpressionTypeSelector
contains a Listbox
to select a ExpressionModel
. On select, the model’s widget replaces the ExpressionTypeSelector
’s widget.
main:
expressionSelector = new ExpressionTypeSelector()
expressionSelector.widget.setParent(layout)
TermModel
(example for an ExpressionModel
)
class TermModel extends ExpressionModel[BooleanTerm] {
val b1 = new ExpressionTypeSelector
val op = new OperatorSelector
val b2 = new ExpressionTypeSelector
var widget = new Hlayout
for (w ← List(
new Label("("),
b1.widget,
op.widget,
b2.widget,
new Label(")")
)) w.setParent(widget)
}
You see: The user can create a tree of TermModel
s. After each selection taking place, it should check if this was the last possible selection.
I don't see any other easy of doing it than using your second option. For that can use Page level event listener. The reference from ZK documentation on it is here