使用 vaadin Page.getCurrent().open() 方法时有没有办法传递参数?

Is there a way to pass parameters when using vaadin Page.getCurrent().open() method?

我正在尝试打开一个 window 或弹出窗口并向其传递一些值。 我想 POST 带参数。

我目前正在使用 vaadin 7.7.6,com.vaadin.server.Page.getCurrent().open() 在新浏览器中打开 url window,不知道如何通过值以及是否可以使其弹出而不是打开新浏览器 window


    private PNativeButton button()
    {
        if (button== null)
        {
            button= new button("Press Me");
            button.getNativeButton().setHeight(36, Unit.PIXELS);
            button.setEnabled(true);
            button.addClickListener(new ClickListener()
            {
                @Override
                public void buttonClick(ClickEvent event)
                {
                    getCurrent().open("https://whosebug.com/", "Pressed", 100, 100, BorderStyle.DEFAULT);
                }
            });
        }
        return button;
    }

我期待一个新的弹出窗口 window,其中 POST url 具有某些参数。

您可以扩展 Window class 并向其添加一些额外的参数。例如:

class MySub extends Window {
    private String message;

    public MySub() {
        super("Sub Window");
        center();
    }

    public void initContent() {
       setContent(new Button(message, event -> close()));
    }

    public void setMessage(String message) {
        this.message = message;
   }
}

并将其用于您的 UI

public static class SubWindowUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        MySub mySub = new MySub();
        mySub.setMessage("Close me !");
        mySub.initContent();

        addWindow(subWindow); // Open it in the UI
    }
}

您没有说明您使用的是哪个 Vaadin 版本。但我猜它是 Vaadin 8。如果这是真的,并且你的 objective 是用外部页面打开浏览器选项卡,我建议使用 BrowserWindowOpener,因为它方便 API添加查询参数。

BrowserWindowOpener opener =
    new BrowserWindowOpener(url);
opener.setParameter("parameter","value");

Button button = new Button("Press me");
opener.extend(button);

上面会打开一个新的浏览器window或标签页,如果你想打开一个弹出窗口Window组件(例如参见其他答案)是更合适的方法。

为了在 Window 组件中显示外国内容,您需要使用 BrowserFrame (which is using iframe) or Embbeded component to wrap the url as component. You can find couple of examples in Vaadin documentation.