Why am I having a communication problem ... when I click the button in the user interface created after clicking on the link in the previous user interface?

I have a strange Vaadin "Communication Problem" error when I try to do the following:

I have two interfaces, the first has a link that points to another interface, here is the code:

public class MenuUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = MenuUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);
        setContent(layout);

        MenuBar menuBar = new MenuBar();

        MenuItem submenu1 = menuBar.addItem("Submenu 1", null);
        MenuItem submenu2 = menuBar.addItem("Submenu 2", null);

        submenu1.addItem("Option 1", null);
        submenu1.addItem("Option 2", null);

        submenu2.addItem("Option 3", null);
        submenu2.addItem("Option 4", new Command() {
            @Override
            public void menuSelected(MenuItem selectedItem) {
                Notification.show("That was option 4");
            }
        });
        layout.addComponent(menuBar);

        Link link = new Link("Go to ShortcutKeys",
                             new ExternalResource(Page.getCurrent().getLocation().toString() + "Shortcut"));
        link.setTargetName("_blank");
        layout.addComponent(link);
    }

}

This interface leads to this: enter image description here

When I click on the link, the new user interface is initialized, here is the code for the new user interface:

public class ShortcutUI extends UI {

    @WebServlet(value = "/Shortcut", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = ShortcutUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);
        setContent(layout);

        final TextField tf = new TextField("Your data:");
        layout.addComponent(tf);

        Button button = new Button("Send data (ENTER)");
        button.setClickShortcut(KeyCode.ENTER, ModifierKey.SHIFT);

        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                layout.addComponent(new Label(tf.getValue()));
                tf.setValue("");
                tf.focus();
            }
        });

        layout.addComponent(button);
    }

It leads to:

enter image description here

Here I type in some text, and then when I click on the "Send Data" button, I get the following:

enter image description here

? , , , ShortcutUI init() MenuUI, :

public class MenuUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = MenuUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);
        setContent(layout);

        MenuBar menuBar = new MenuBar();

        MenuItem submenu1 = menuBar.addItem("Submenu 1", null);
        MenuItem submenu2 = menuBar.addItem("Submenu 2", null);

        submenu1.addItem("Option 1", null);
        submenu1.addItem("Option 2", null);

        submenu2.addItem("Option 3", null);
        submenu2.addItem("Option 4", new Command() {
            @Override
            public void menuSelected(MenuItem selectedItem) {
                Notification.show("That was option 4");
            }
        });
        layout.addComponent(menuBar);

        Link link = new Link("Go to ShortcutKeys",
                             new ExternalResource(Page.getCurrent().getLocation().toString() + "Shortcut"));
        link.setTargetName("_blank");
        layout.addComponent(link);

        // Shortcut Keys
        final TextField tf = new TextField("Your data:");
        layout.addComponent(tf);

        Button button = new Button("Send data (ENTER)");
        button.setClickShortcut(KeyCode.ENTER, ModifierKey.SHIFT);

        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                layout.addComponent(new Label(tf.getValue()));
                tf.setValue("");
                tf.focus();
            }
        });

        layout.addComponent(button);
    }

}

:

enter image description here

. (" " " " - , " ").

, , , Click, , " " Vaadin?

debug Vaadin:

Communication error: (SyntaxError) : Unexpected token < - Original JSON-text: html> 
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta 
http-equiv="X-UA-Compatible" content="IE=11;chrome=1" /> <style type="text/css">html, 
body {height:100%;margin:0;}</style> <link rel="shortcut icon" 
type="image/vnd.microsoft.icon" 
href="./../../VAADIN/themes/chapter_4_menubar_and_shortcutkeys/favicon.ico" /> <link 
rel="icon" type="image/vnd.microsoft.icon" 
href="./../../VAADIN/themes/chapter_4_menubar_and_shortcutkeys/favicon.ico" /> </head> 
<body scroll="auto" class=" v-generated-body"> <div id="Chapter4MenuBarandShortcutKeys-
1103734620" class=" v-app chapter_4_menubar_and_shortcutkeys"> <div class=" v-app-
loading"></div> <noscript> You have to enable javascript in your browser to use an  
application built with Vaadin. </noscript> </div> <script type="text/javascript" 
src="./../../VAADIN/vaadinBootstrap.js"></script> <script type="text/javascript">//<!
[CDATA[ if (!window.vaadin) alert("Failed to load the bootstrap javascript: 
./../../VAADIN/vaadinBootstrap.js"); if (typeof window.__gwtStatsEvent != 'function') { 
vaadin.gwtStatsEvents = []; window.__gwtStatsEvent = function(event) 
{vaadin.gwtStatsEvents.push(event); return true;}; } 
vaadin.initApplication("Chapter4MenuBarandShortcutKeys-1103734620",{ "authErrMsg": { 
"caption": "Authentication problem", "message": "Take note of any unsaved data, and 
<u>click here<\/u> or press ESC to continue." }, "comErrMsg": { "caption": "Communication 
problem", "message": "Take note of any unsaved data, and <u>click here<\/u> or press ESC 
to continue." }, "debug": true, "heartbeatInterval": 300, "serviceUrl": "./../..", 
"sessExpMsg": { "caption": "Session Expired", "message": "Take note of any unsaved data, 
and <u>click here<\/u> or press ESC key to continue." }, "standalone": true, "theme": 
"chapter_4_menubar_and_shortcutkeys", "vaadinDir": "./../../VAADIN/", "versionInfo": 
{"vaadinVersion": "7.3.7"}, "widgetset": "com.vaadin.DefaultWidgetSet" }); //]]></script> 
</body> </html

?

+4
1

, ​​, - , .

VaadinServlet, ShortcutUI:

:

 @WebServlet(value = "/Shortcut", asyncSupported = true)

:

 @WebServlet(value = "/Shortcut/*", asyncSupported = true)

, ShortcutUI , URL-, :

http://localhost:8080/myapp/Shortcut/UIDL/?v-uiId=0

/myapp, :

http://localhost:8080/Shortcut/UIDL/?v-uiId=0

DocumentRoot (, Maven, mvn mvn jetty:run Jetty).

/Shortcut /Shortcut/UIDL/?v-uiId=0, , . Shortcut/* , "/*" Shortcut /UIDL/?v-uiId=0.

: " " ( , /*) :

@WebServlet(value = "/*", asyncSupported = true)

:

@WebServlet(urlPatterns = { "", "/VAADIN/*" }, asyncSupported = true)

!. , Vaadin /HEARTBEAT ( "/UIDL" ). - , "*" ( "/HEARTBEAT", "/UIDL" ..).

, IMHO :

@WebServlet(value = "/*", asyncSupported = true)

MenuUI :

@WebServlet(value = "/Shortcut/*", asyncSupported = true)

ShortcutUI "-UI" , .

Navigator API → https://vaadin.com/book/-/page/advanced.navigator.html

+6

Source: https://habr.com/ru/post/1568370/


All Articles