webfirmframework for Java Experts
ParentGainedListener & ParentLostListener since wffweb-12.0.1
ParentGainedListener
& ParentLostListener
can be added on any tag.
If a tag gains a parent or loses its parent by the framework (eg: whenURI
event) then also the listeners will get invoked.
ParentGainedListener
ParentGainedListener
can be used to get an event when a tag gains a parent. When a
ParentGainedListener
is added using
addParentGainedListener
it will return an id of its internal slot, this id can be used to
remove that listener from the tag using
removeParentGainedListener
method, see the following example.
Div div1 = new Div(null);
Div div2 = new Div(null);
long listenerSlotId = div1.addParentGainedListener(event -> {
System.out.println("addParentGainedListener invoked");
});
//this line will invoke addParentGainedListener
div2.appendChild(div1);
//this will remove the listener added to the tag
div1.removeParentGainedListener(listenerSlotId);
ParentLostListener
ParentLostListener
can be used to get an event when a tag loses its parent. When a
ParentLostListener
is added using
addParentLostListener
it will return an id of its internal slot, this id can be used to
remove that listener from the tag using
removeParentLostListener
method, see the following example.
Div div1 = new Div(null);
Div div2 = new Div(null);
div2.appendChild(div1);
long listenerSlotId = div1.addParentLostListener(event -> {
System.out.println("addParentLostListener invoked");
});
//this line will invoke addParentLostListener
div2.removeChild(div1); // or div2.removeAllChildren();
//this will remove the listener added to the tag
div1.removeParentLostListener(listenerSlotId);
Note: The listener slot id is NOT globally unique, it is unique only for the corresponding tag.