Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Composite UI components may not handle UI events #695
Browse files Browse the repository at this point in the history
  • Loading branch information
glebfox committed Oct 18, 2021
1 parent b20d97a commit 2e5cfab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 7 additions & 11 deletions ui/src/main/java/io/jmix/ui/component/CompositeComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.vaadin.ui.AbstractComponent;
import io.jmix.core.annotation.Internal;
import io.jmix.core.common.event.EventHub;
import io.jmix.core.common.event.Subscription;
Expand Down Expand Up @@ -149,20 +148,15 @@ protected void setComposition(T composition) {
Preconditions.checkState(root == null, "Composition root has already been initialized");
this.root = composition;

root.withUnwrapped(AbstractComponent.class, component -> {
component.addAttachListener(event -> enableEventListeners());
component.addDetachListener(event -> disableEventListeners());
});

// Add id prefix to root and all nested component id to uniquely identify them
updateComponentIds();
updateComponentIds(composition);
}

protected void updateComponentIds() {
updateIdIfNeeded(root);
protected void updateComponentIds(T composition) {
updateIdIfNeeded(composition);

if (root instanceof HasComponents) {
for (Component component : ((HasComponents) root).getComponents()) {
if (composition instanceof HasComponents) {
for (Component component : ((HasComponents) composition).getComponents()) {
updateIdIfNeeded(component);
}
}
Expand Down Expand Up @@ -289,6 +283,7 @@ public boolean isAttached() {
@Override
public void attached() {
((AttachNotifier) getComposition()).attached();
enableEventListeners();

if (hasSubscriptions(AttachEvent.class)) {
publish(AttachEvent.class, new AttachEvent(this));
Expand All @@ -298,6 +293,7 @@ public void attached() {
@Override
public void detached() {
((AttachNotifier) getComposition()).detached();
disableEventListeners();

if (hasSubscriptions(DetachEvent.class)) {
publish(DetachEvent.class, new DetachEvent(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public TestEventPanel() {
}

protected void onCreate(CreateEvent event) {
CssLayout layout = uiComponents.create(CssLayout.NAME);
setComposition(layout);
root = uiComponents.create(CssLayout.NAME);
}

public int getEventCounter() {
Expand Down

0 comments on commit 2e5cfab

Please sign in to comment.