2

In my Vaadin Flow 24 application, I have a view:

@Route(value = "embedded/jobables/recent")
@AnonymousAllowed
public class RecentJobablesEmbeddedView extends VerticalLayout implements HasUrlParameter<String> {
...
}

which is also component(extended from VerticalLayout).

I'd like to export this component to be able to embed it into non-Vaadin HTML page.

I created the following exporter class:

public class RecentJobablesEmbeddedExporter extends WebComponentExporter<RecentJobablesEmbeddedView> {

    protected RecentJobablesEmbeddedExporter(String tag) {
        super("recent-jobables-embedded-view");
    }

    @Override
    protected void configureInstance(WebComponent<RecentJobablesEmbeddedView> webComponent, RecentJobablesEmbeddedView recentJobablesEmbeddedView) {

    }

}

Right now I'm unable to access:

http://localhost:8080/vaadin/web-component/recent-jobables-embedded-view.js

Vaadin flow application returns 404 Page Not Found.

What am I doing wrong and how to fix it?

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • Just to be sure: have you mapped the Vaadin servlet to /vaadin/*, since the url you are trying to access is http://localhost:8080/vaadin/web-component/recent-jobables-embedded-view.js? – Marco C Jun 30 '23 at 17:37
  • Yes, correct. The default mapping with Spring Boot 3 – alexanoid Jul 05 '23 at 15:44
  • 1
    With Spring Boot by default the Vaadin servlet is mapped to `/*`. The `/vaadin/*` in the example may be a bit confusing, because it has nothing to do with the reserved `/VAADIN/` path used by the servlet. If you don't have set the `vaadin.urlMapping` property in application.properties, you should probably use `http://localhost:8080/web-component/recent-jobables-embedded-view.js` – Marco C Jul 05 '23 at 16:34
  • I have similar problem and not even the /web-component/tag-name.js works. Only returns "Route not available"- page. Confirmed in debugger that the WebComponentExporter constructor is never called. Is there something else to do when registering the exporter? – eeq Jul 14 '23 at 09:00

1 Answers1

1

The WebComponentExporter implementation must have a public default constructor. In your sample code, it is protected and it takes an argument.

If you check the server logs, you should see a message like

Class RecentJobablesEmbeddedExporter has no public no-argument constructor, and won't be instantiated as a 'WebComponentExporter' by default
Marco C
  • 706
  • 4
  • 6