Giter VIP home page Giter VIP logo

vaadin-jsp-integration-example's Introduction

vaadin-jsp-integration-example

Check this add-on to automate the rendering of Vaadin UIs in JSP files.

This example shows how to add a Vaadin UI into a JSP page.

Alt text

Steps

To include a new Vaadin UI into an existing JSP page, follow these steps:

1. Add Vaadin dependencies:

2. Implement a new Vaadin UI:

  • Add the Vaadin UI class:
@Theme("valo")
public class ExampleVaadinUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        setContent(new Label("This is a Vaadin UI");
    }
}
  • Add a Vaadin Servlet mapped to a custom url. This can be done using annotations, for example:
...
public class ExampleVaadinUI extends UI {
    ...
    
    @WebServlet(urlPatterns = {"/example-ui/*", "/VAADIN/*"}, name = "ExampleVaadinUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = ExampleVaadinUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }

}
  • Add a GWT module definition file. For example, you can add the file ExampleVaadinUIWidgetset.gwt.xml in the src/main/resources/com/example/ui directory.
  • Annotate the Vaadin UI implementation class with @Widgetset and the appropriate widgetset name. For example:
...
@Widgetset("com.example.ui.ExampleVaadinUiWidgetset")
public class ExampleVaadinUI extends UI {
    ...
}
  • Compile the widgetset. If you are using Maven, run the following:
mvn vaadin:compile
  • Deploy the application and check that you can see the Vaadin UI. Remember to add the correct url according to what you configured as urlMappings in the VaadinServlet. For the previous example, it could be something like http://localhost:8080/example-ui.

3. Add the Vaadin application into the JSP page:

  • Add an HTML div element to be used as target for the Vaadin UI. Example:
<div id="example-vaadin-ui" class="v-app valo example-vaadin-ui" style="height: 320px">
    <div class="v-app-loading"></div>
    <noscript>
        You have to enable javascript in your browser to use an application built with Vaadin.
    </noscript>
</div>
  • Include Vaadin's bootstrap script:
<script type="text/javascript" src="./VAADIN/vaadinBootstrap.js?v=7.6.2"></script>
  • Call the vaadin.initApplication() function. Example:
<script type="text/javascript">//<![CDATA[
    vaadin.initApplication("example-vaadin-ui", {
        "theme": "valo",
        "versionInfo": {
            "vaadinVersion": "7.6.2"
        },
        "widgetset": "com.example.ui.ExampleVaadinUiWidgetset",
        "comErrMsg": {
            "caption": "Communication problem",
            "message": "Take note of any unsaved data, and <u>click here</u> or press ESC to continue.",
            "url": null
        },
        "authErrMsg": {
            "caption": "Authentication problem",
            "message": "Take note of any unsaved data, and <u>click here</u> or press ESC to continue.",
            "url": null
        },
        "sessExpMsg": {
            "caption": "Session Expired",
            "message": "Take note of any unsaved data, and <u>click here</u> or press ESC key to continue.",
            "url": null
        },
        "vaadinDir": "./VAADIN/",
        "debug": true,
        "standalone": false,
        "heartbeatInterval": 300,
        "browserDetailsUrl": "/example-ui",
        "serviceUrl": "/example-ui"
    });
//]]></script>

For more information about embedded Vaadin UIs see https://vaadin.com/docs/-/part/framework/advanced/advanced-embedding.html.

vaadin-jsp-integration-example's People

Contributors

alejandro-du avatar viydaag1 avatar

Watchers

James Cloos avatar Jean-Christophe Fortier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.