简体   繁体   English

Vaadin上传组件receiveUpload()方法

[英]Vaadin upload component receiveUpload() method

I want to upload a recorded file in vaadin. 我想用vaadin上传录制的文件。 I am using the upload component of vaadin. 我正在使用vaadin的上传组件。 But the problem is that I dont want to show the file dialog, rather I would like to fire events to upload component from my own buttons. 但是问题是我不想显示文件对话框,而是希望触发事件以从我自己的按钮上载组件。 I have written a class which is extended by Upload component and called its fireUploadSuccess() method, this event is successfully fired. 我编写了一个由Upload组件扩展的类,并将其称为fireUploadSuccess()方法,此事件已成功触发。 But I want to invoke the receiveUpload() method manually, I mean by firing some event from my own button to invoke this method. 但是我想手动调用receiveUpload()方法,这意味着从我自己的按钮中触发一些事件来调用此方法。 Any solution friends ? 任何解决方案的朋友? Thanks! 谢谢!

Normally, in the base Upload Class, when the fireUploadSuccess() is called, the uploadSucceeded method of the attached class is normally called. 通常,在基本的上载类中,当调用fireUploadSuccess()时,通常会调用附加类的uploadSucceeded方法。

If you really changed the method, you maybe forgot the super() statement ? 如果您真的改变了方法,您可能会忘记super()语句?

Could you also please show us an example of your modified class if you can 如果可以的话,还可以请您向我们展示您的已修改课程的示例

here is a process that i used. 这是我使用的过程。

i created a custom class named MyFileReceive which implements Receiver interface of Upload.java file. 我创建了一个名为MyFileReceive的自定义类,该类实现Upload.java文件的Receiver接口。 There i override the method receiveUpload() and did what i want to do when uploaded file is received. 在那里,我重写了方法receiveUpload()并且在接收上载文件时做了我想做的事情。 Put the instance of MyFileReceiver class into the constructor of Upload class. 将MyFileReceiver类的实例放入Upload类的构造函数中。 Hope it will work.. 希望它能工作..

    public class MyUI extends UI{
       private MyUI.MyFileReceiver receiver = new MyUI.MyFileReceiver();
       private Upload upload;
       protected void init(VaadinRequest vaadinRequest) {
            .............
            .......................
            upload = new Upload(null, receiver);
            upload.addSucceededListener((SucceededEvent event) -> {
            //Do what you want to do
    });
    public class MyReceiver implements Receiver {
        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
        //do what you want to do when receive upload
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM