Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add RouterLayout as bean classes #85

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -94,6 +94,18 @@ public void build(
.produce(new BeanDefiningAnnotationBuildItem(ROUTE_ANNOTATION));
}

@BuildStep
public void specifyRouterLayoutBeans(CombinedIndexBuildItem item,
BuildProducer<AdditionalBeanBuildItem> additionalBeanProducer) {
Collection<ClassInfo> 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<AdditionalBeanBuildItem> additionalBeanProducer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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());
}

}