Good morning
I noticed that the ordering of my grid stopped working since version 8.3.2, but in version 8.3.1 it works perfectly, what has changed?
My code:
package br.com.passella.teste1;
import java.util.ArrayList;
import java.util.stream.Stream;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.provider.AbstractBackEndDataProvider;
import com.vaadin.data.provider.Query;
import com.vaadin.external.org.slf4j.Logger;
import com.vaadin.external.org.slf4j.LoggerFactory;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
/**
* This UI is the application entry point. A UI may either represent a browser
* window (or tab) or some part of an HTML page where a Vaadin application is
* embedded.
* <p>
* The UI is initialized using {@link #init(VaadinRequest)}. This method is
* intended to be overridden to add component to the user interface and
* initialize non-component functionality.
*/
@Theme("mytheme")
public class MyUI extends UI {
private static final long serialVersionUID = -4540232988161842127L;
public static class Person {
private String name;
private Integer age;
public Person(String name, Integer age) {
this.setName(name);
this.setAge(age);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
public static class PersonDataProvider extends AbstractBackEndDataProvider<Person, Void> {
private static final long serialVersionUID = -8537383384848609803L;
private ArrayList<Person> people = buildPeople();
private ArrayList<Person> buildPeople() {
ArrayList<Person> result = new ArrayList<>();
result.add(new Person("Person A", 10));
result.add(new Person("Person B", 20));
result.add(new Person("Person C", 2));
result.add(new Person("Person D", 7));
return result;
}
@Override
protected Stream<Person> fetchFromBackEnd(Query<Person, Void> query) {
return people.stream();
}
@Override
protected int sizeInBackEnd(Query<Person, Void> query) {
return people.size();
}
}
public static class GridPerson extends Grid<Person> {
private static final Logger logger = LoggerFactory.getLogger(GridPerson.class);
private static final long serialVersionUID = -1881388823871233410L;
public GridPerson() {
setDataProvider(new PersonDataProvider());
addSortListener(event -> event.getSortOrder()
.forEach(gso -> logger.info("Sorting...." + gso.getSorted().getCaption())));
buildColumns();
}
private void buildColumns() {
addColumn(Person::getName)
.setEditorBinding(
getEditor().getBinder().forField(new TextField()).bind(Person::getName, Person::setName))
.setCaption("Name").setSortable(true).setSortProperty("name");
addColumn(Person::getAge).setEditorBinding(getEditor().getBinder().forField(new TextField())
.withConverter(new StringToIntegerConverter("Invalid!")).bind(Person::getAge, Person::setAge))
.setCaption("Age").setSortable(true).setSortProperty("age");
}
}
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
setContent(layout);
layout.addComponent(new GridPerson());
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
private static final long serialVersionUID = 4173226803747459960L;
}
}
Thanks