kalsowerus
kalsowerus

Reputation: 1008

Vaadin GridLayout not updating correctly

I have a problem where Vaadin does not update the display of a GridLayout in time. The GridLayout is a component in a VerticalLayout, that I use to list all uploaded files. When I upload a file everything works fine on the server-side but the client does not see the change until he creates a new request to the server (by uploading another file or triggering some other event / rarely the update works fine though).

Here is the component that contains the problematic GridLayout:

public class ListedMultiFileUpload extends VerticalLayout {
    private MultiFileUpload multiFileUpload;
    private GridLayout fileList;

    public ListedMultiFileUpload(UploadFinishedHandler uploadFinishedHandler, UploadStateWindow uploadStateWindow) {
        multiFileUpload = new MultiFileUpload(uploadFinishedHandler, uploadStateWindow);
        fileList = new GridLayout(2, 5);
        fileList.setImmediate(true);

        addComponents(multiFileUpload, fileList);
    }

    public SmartMultiUpload getSmartUpload() {
        return multiFileUpload.getSmartUpload();
    }

    public void addFile(String fileName, final Runnable fileRemover) {
        final Label label = new Label(fileName);
        final Button button = new Button("X");
        button.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                fileList.removeComponent(label);
                fileList.removeComponent(button);
                fileRemover.run();
            }
        });
        fileList.addComponent(label);
        fileList.addComponent(button);
        markAsDirtyRecursive();
    }
}

I already tried setting the GridLayout to immediate as well as marking the whole component as dirty but nothing seems to make a difference.

So basically am I doing something wrong here? Or if not, is there a "nice" way I could force the client to update its components?

Upvotes: 0

Views: 124

Answers (1)

kalsowerus
kalsowerus

Reputation: 1008

As proposed by @Morfic I enabled the Server-Push addon in automatic mode and now the required updates to the client are made by that addon. Not sure how much I like that solution but it works.

Upvotes: 0

Related Questions