I am writing a filter to filter person names which are displayed in a column pertaining to a vaadin grid. I add a data provider with row objects as follows:
ListDataProvider<Row> dataProvider = new ListDataProvider<>(dataSet.getRows());
Grid.Column<Row, Object> colName = grid.addColumn(row -> row.getValue("NAME")).setCaption("NAME");
grid.setDataProvider(dataProvider);
HeaderRow filterRow = grid.appendHeaderRow();
RowFilter filterObject = new RowFilter();
dataProvider.setFilter(row -> filterObject.test(row, "NAME"));
TextField nameField = new TextField();
nameField.addValueChangeListener(event -> {
filterObject.setName(event.getValue());
dataProvider.refreshAll();
});
nameField.setValueChangeMode(ValueChangeMode.EAGER);
filterRow.getCell(colName).setComponent(nameField);
nameField.setSizeFull();
nameField.setPlaceholder("Filter");
nameField.getElement().setAttribute("focus-target", "");
The row filter looks as follows:
package com.example.vaadin.utils;
import org.apache.commons.lang3.StringUtils;
public class RowFilter {
String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean test(com.example.vaadin.views.ContactView.Row row, String columnval) {
if (name.length() > 0 && !StringUtils
.containsIgnoreCase(String.valueOf(row.getValue(columnval)),
name)) {
return false;
}
return true;
}
}
Here is my row class:
package com.example.vaadin.utils;
import org.apache.commons.lang3.StringUtils;
public class RowFilter {
String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean test(com.example.vaadin.views.ContactView.Row row, String columnval) {
if (name.length() > 0 && !StringUtils
.containsIgnoreCase(String.valueOf(row.getValue(columnval)),
name)) {
return false;
}
return true;
}
}
The problem is the following one:
When I want to add the attribute focus-target to the nameField like this - nameField.getElement().setAttribute("focus-target", ""); - but com.vaadin.ui.TextField does not seem to have a getElement method in vaadin 8. I have been looking for a workaround to get this problem fixed, but to no avail. This is why I’d like to ask here whether anybody can tell me if there is one.