Embeddeding applications is an alternative to writing monolithic frontends for your applications.
Embedded applications are also know as micro frontends. They are isolated and self-contained pieces of code that can be maintained by different teams, using different frameworks. A simple example is an embedded calendar in a web page: the calendar functionality is isolated and has no relation to the logic of the main application.
Embedding an application is similar to adding a client-side widget to a page, except the embedded application has back-end logic and is a real application in its own right.
Vaadin allows you to embed applications using web components and provides the
WebComponentExporter class for this purpose.
These are the basic steps to creating an embedded application:
Create the application that will be embedded and export it:
Write and declare a server-side component in a specific way, using a custom element tag name.
Create an exporter for the component by extending the
Embed and use the application in your host (embedding) page.
Make your page aware of the application by adding an element with a matching custom tag.
The embedded application behaves like a standard Vaadin component, regardless of any other content on the page, except that certain features are not available. See Embedded Application Limitations for more.
To create an embedded application, you need to export a component as an embeddable application:
Create the component (
MyComponent) that will be used as the embedded application. You can create a new component or use an existing one. This component (application) has no relation to the host application.
Create an exporter for the component, by extending the
Implement its constructor providing the tag name that you will use to identify it on the host application.
Configure properties in the constructor using the
configureInstancemethod, if you need additional initialization of the exported component (for example, add a listener to the original component).
Deploy your embeddable application.
See Creating an Embedded Vaadin Application Tutorial for a detailed example.
To embed the exported application in a page:
webcomponent-loader.jspolyfill script to your page, for example
YOUR_EMBEDDED_APPLICATION_URIis the URI at which you deploy your exported application. This depends on how and where you deploy the application.
While the example above uses the polyfill provided with Vaadin, you can use any CDN (such as unpkg.com).
Import the web component URL resource of the embedded application, for example
<script type='module' src='YOUR_EMBEDDED_APPLICATION_URI/web-component/my-component.js'></script>.
The application is imported using the path
"web-component"is the base path for embeddable applications, and
YOUR_EMBEDDED_APPLICATION_URIis the URI at which you deploy your exported application.
Use the embedded web component in your HTML code using the tag name you assigned to the embedded application, for example
The tag name,
"my-component", is used to identify the embedded application.
my-componentis used in your HTML page content. This can be a static HTML file or content generated by any framework, for example a plain servlet, JSP, and more.
For more on embedded applications, see: