Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Update TextField dynamicly

David Askirk
1 decade ago Apr 09, 2010 11:56am

Hi

I have a TextField which I update when some data receives from an external source.

The view is not updated until I click a button, which do not have any listener added.

The gioal is to create a terminal component.

In the dataReceived function have I tried to use the validate() function, requestRepaint and use the valuechanged event.

Now for some code snippets:

Where the data is received:

@Override
    public void dataReceived(SshDataReceivedEvent sshDataReceivedEvent) {
        output.setReadOnly(false);
        this.output.setValue(output.getValue()+sshDataReceivedEvent.getData());
        output.setReadOnly(true);
    }

The creation of the GUI:

private void createUi(String caption) {

        cssLayout = new CssLayout() {
             @Override
            protected String getCss(Component c) {
                // colorize every third rendered brick
                if (c instanceof TextField) {
                    return "color: #00FF00; background-color: #000000;";
                }
                return null;
             }
        };

        output.setRows(24);
        output.setColumns(80);
        output.setReadOnly(true);
        output.setCaption("Command output");

        input.setColumns(80);
        input.setInputPrompt("command... ");
        input.setImmediate(true);
        input.addListener(this);

        executeButton.setCaption("Update view");
        this.addComponent(cssLayout);

        cssLayout.addComponent(output);
        cssLayout.addComponent(input);
        cssLayout.addComponent(executeButton);
    }
Henri Kerola
1 decade ago Apr 12, 2010 5:47pm

Hi,

The problem is that changes from the server-side cannot be pushed to the client-side. So the browser won't be refreshed until the client sends a request to the server. You can use ProgressIndicator or Refresher to poll UI changes.

-Henri