0

我正在使用 Vaadin 和 Liferay6.0 创建一个 Portlet 项目。我需要从 ui 上传一个 csv 文件并读取该文件。我的课是这样的:

@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();
    }
}

谢谢 Hiamsnhu

4

1 回答 1

1

我正在做同样的事情,在阅读您的代码时,我发现您忘记了:

window.addComponent(updateBttn);

希望这有效。

于 2012-04-05T10:56:34.630 回答