开发者

How do I upload file in Vaadin ui Portlet?

开发者 https://www.devze.com 2023-04-04 17:54 出处:网络
I am creating a Portlet project using Vaadin and Liferay6.0. I need to upload a csv file from ui and read the file.

I am creating a Portlet project using Vaadin and Liferay6.0. I need to upload a csv file from ui and read the file. My class is as fllows:

@SuppressWarnings("serial")
public void init() {
    Window window = new Window("Vaadin Portlet Application");
    setMainWindow(window);
    window.addComponent(new Label("Hello Vaadin user!"));
    window.addComponent(new Label("We are here"));
    final TextField tf = new TextField("Device Name:");

    // Create the Upload component.
    final Upload upload =
            new Upload("Upload the file here", null);

    // Use a custom button caption instead of plain "Upload".
    upload.setButtonCaption("Upload Now");



    try{

        System.out.println("I am here only");
        final DeviceManager dManager = new DeviceManager();
        final DeviceSoap[] devices = dManager.getAll();
        //getDeviceByName("207.20.47.137");
        for (DeviceSoap deviceSoap : devices) {
            window.addComponent(new Label("Device Name! "+deviceSoap.getName()));

        }


        window.addComponent(tf);
        Button submitBttn = new Button("Add Device");
        Button updateBttn = new Button("Update Device");
        window.addComponent(submitBttn);            

        // Handle button clicks
        submitBttn.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                // If the field value is bad, set its error.
                // (Allow only alphanumeric characters.)
                DeviceSoap d = new DeviceSoap();
                d.setName(tf.getValue().toString());
                try {
                    dManager.createDevice(d);
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });


        updateBttn.addListener(new Button.ClickListener() {
 开发者_开发百科           @Override
            public void buttonClick(ClickEvent event) {
                // If the field value is bad, set its error.
                // (Allow only alphanumeric characters.)
                DeviceSoap d = devices[1];
                d.setName(tf.getValue().toString());
                try {
                    dManager.createDevice(d);
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });         


        upload.addListener((Upload.SucceededListener) this);
        upload.addListener((Upload.FailedListener) this);
        window.addComponent(upload);
    }catch(Exception e){
        e.printStackTrace();
    }
}

Thanks Hiamsnhu


I'm doing the same thing, and in reading your code, I see that you forgot making:

window.addComponent(updateBttn);

Hope this works.

0

精彩评论

暂无评论...
验证码 换一张
取 消