Vaadin UI code snippets

We have a list of useful code snippets for you. Simply use them for your application. All snippets are free to use and licensed under Apache 2.0.

Checkbox in Table Header

If you want to show a checkbox in the table header of a v7 Table:

use following code:

    .setLabel("<input type='checkbox' id='checkboxSelectAll' onclick=\"selectAllListener(this.checked)\" " +
              "style=\"position:absolute;top: 2px;\"/>");

and to receive events from the checkbox:

JavaScript.getCurrent().addFunction("selectAllListener", new JavaScriptFunction() 
    public void call(JsonArray arguments) 

Checkbox in Grid Header

If you want to show a checkbox in the header of a Grid:

use following code:

CheckBox cbx = new CheckBox();
cbx.addValueChangeListener(new ValueChangeListener<Boolean>()
    public void valueChange(ValueChangeEvent<Boolean> event)
UIFactoryManager.getFactory().invokeLater(() ->
    // Cast the resource to a Grid.
        // Get the first (automatically added) row.
        // Get the cell for the column we want.
        // Add the component.

Disable autocomplete

You have different options:

1) Disable for a specific editor


2) Disable for the cell editor

ICellEditor ced = UICellEditor.getCellEditor(book, "COLUMN");
//if you set a custom cell editor	
if (ced instanceof UICellEditor)
    ced = (ICellEditor)((UICellEditor)ced).getUIResource();

Be careful with cell editors, because if no custom cell editor was set, the default (global) cell editors will be used. If you change the autocomplete feature for the global text cell editor, all editors are affected.

It's a good idea to set a custom cell editor:

book.getRowDefinition().getColumnDefinition("COLUMN").getDataType().setCellEditor(new UITextCellEditor());
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information