diff --git a/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java b/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java index 7fc141b..e2a8edd 100644 --- a/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java +++ b/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java @@ -16,7 +16,6 @@ package com.vaadin.quarkus.deployment; import javax.servlet.annotation.WebServlet; - import java.util.ArrayList; import java.util.Collection; import java.util.Objects; @@ -46,9 +45,12 @@ import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.vaadin.flow.router.HasErrorParameter; import com.vaadin.flow.router.Route; +import com.vaadin.flow.router.RouterLayout; import com.vaadin.flow.server.VaadinServlet; import com.vaadin.quarkus.QuarkusVaadinServlet; import com.vaadin.quarkus.WebsocketHttpSessionAttachRecorder; @@ -64,8 +66,6 @@ import com.vaadin.quarkus.context.UIScopedContext; import com.vaadin.quarkus.context.VaadinServiceScopedContext; import com.vaadin.quarkus.context.VaadinSessionScopedContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; class VaadinQuarkusProcessor { @@ -94,6 +94,18 @@ public void build( .produce(new BeanDefiningAnnotationBuildItem(ROUTE_ANNOTATION)); } + @BuildStep + public void specifyRouterLayoutBeans(CombinedIndexBuildItem item, + BuildProducer additionalBeanProducer) { + Collection layouts = item.getComputingIndex() + .getAllKnownImplementors( + DotName.createSimple(RouterLayout.class.getName())); + for (ClassInfo layoutInfo : layouts) { + additionalBeanProducer.produce(AdditionalBeanBuildItem + .unremovableOf(layoutInfo.name().toString())); + } + } + @BuildStep public void specifyErrorViewsBeans(CombinedIndexBuildItem item, BuildProducer additionalBeanProducer) { diff --git a/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjection.java b/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjection.java new file mode 100644 index 0000000..b2f23ad --- /dev/null +++ b/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjection.java @@ -0,0 +1,25 @@ +package com.vaadin.flow.quarkus.it.layout; + +import javax.inject.Inject; + +import com.vaadin.flow.component.AttachEvent; +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.Span; +import com.vaadin.flow.quarkus.it.Counter; +import com.vaadin.flow.router.RouterLayout; + +public class LayoutWithInjection extends Div implements RouterLayout { + + public static final String LAYOUT_COUNTER_ID = "layoutCounter"; + + @Inject + Counter counter; + + @Override + protected void onAttach(AttachEvent attachEvent) { + int value = counter.increment(LayoutWithInjection.class.getName()); + Span span = new Span("Counter: " + value); + span.setId(LAYOUT_COUNTER_ID); + getElement().appendChild(span.getElement()); + } +} diff --git a/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjectionView.java b/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjectionView.java new file mode 100644 index 0000000..998c047 --- /dev/null +++ b/integration-tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/layout/LayoutWithInjectionView.java @@ -0,0 +1,9 @@ +package com.vaadin.flow.quarkus.it.layout; + +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.router.Route; + +@Route(value = "injected-layout-view", layout = LayoutWithInjection.class) +public class LayoutWithInjectionView extends Div { + +} diff --git a/integration-tests/common-test-code/src/test/java/com/vaadin/flow/quarkus/it/LayoutWithInjectionIT.java b/integration-tests/common-test-code/src/test/java/com/vaadin/flow/quarkus/it/LayoutWithInjectionIT.java new file mode 100644 index 0000000..dc2e990 --- /dev/null +++ b/integration-tests/common-test-code/src/test/java/com/vaadin/flow/quarkus/it/LayoutWithInjectionIT.java @@ -0,0 +1,28 @@ +package com.vaadin.flow.quarkus.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.flow.quarkus.it.layout.LayoutWithInjection; + +@QuarkusIntegrationTest +class LayoutWithInjectionIT extends AbstractCdiIT { + + @Override + protected String getTestPath() { + return "/injected-layout-view"; + } + + @Test + void layout_injectedComponent() { + open(); + WebElement spanElement = waitUntil(driver -> driver + .findElement(By.id(LayoutWithInjection.LAYOUT_COUNTER_ID))); + + Assertions.assertEquals("Counter: 1", spanElement.getText()); + } + +}