编程语言
首页 > 编程语言> > java-单击MenuItem打开上载窗口

java-单击MenuItem打开上载窗口

作者:互联网

我想通过单击MenuItem从Upload元素打开uploadwindow.这可能吗?
另一个想法是在MenuBar中添加上载元素,但是我认为这是不可能的,对吧?

感谢帮助!

解决方法:

也许一些JavaScript可以帮助您:

Upload upload = new Upload();
upload.setImmediate(true); // if you want to start upload after selection
upload.addStyleName("my-upload");
MenuBar menuBar = new MenuBar();
menuBar.addItem("Caption", new Command() {
    private static final long serialVersionUID = 1L;

    @Override
    public void menuSelected(MenuItem selectedItem) {
        JavaScript.getCurrent().execute(
            "document.getElementsByClassName('gwt-FileUpload')[0].click()");
    }
});
addComponent(upload);
addComponent(menuBar);

如果要隐藏上载:

.v-slot-my-upload {
    display: none;
}

标签:vaadin,menu,upload,java
来源: https://codeday.me/bug/20191121/2049830.html