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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Filtering with Datefield and SimpleStringFilter not filtering.
I'm learning how to add filter fields in a grid by following the tutorial So far it's great! I can add the filters in a row! But I have a column with dates, and wanted to implement a datefield in the filter.
I need help troubleshooting why this is happening.
So what I have is this:
BeanItemContainer<Bean> beanList = new BeanItemContainer<Bean>(Bean.class);
Grid resultsGrid = new Grid();
resultsGrid.setContainerDataSource(beanList);
HeaderRow filterRow = resultsGrid.appendHeaderRow();
for (Object pid: resultsGrid.getContainerDataSource().getContainerPropertyIds()){
HeaderCell cell = filterRow.getCell(pid);
if (pid.toString().contains("date")){
DateField filterDate = new DateField();
filterDate.setHeight("15px");
filterDate.setStyleName("filterField");
filterDate.setDateFormat("MM-dd-yyyy");
filterDate.addValueChangeListener(change ->{beanList.removeContainerFilters(pid);
if (change.getProperty() !=null)
System.out.println(filterDate.getValue().toString());
SimpleDateFormat filterFormat = new SimpleDateFormat("MM-dd-yyyy");
try{
System.out.println(filterFormat.format(filterDate.getValue()));
}catch(Exception e){
e.printStackTrace();
}
try{
beanList.addContainerFilter(new SimpleStringFilter(pid,filterFormat.format(filterDate.getValue()),true,false));
}catch(Exception e){
e.printStackTrace();
}
});
cell.setComponent(filterDate);
}else {
TextField filterField = new TextField();
filterField.setColumns(5);
filterField.setWidth("100%");
filterField.setHeight("15px");
filterField.setStyleName("filterField");
filterField.addTextChangeListener(change ->{beanList.removeContainerFilters(pid);
if (! change.getText().isEmpty())
beanList.addContainerFilter(new SimpleStringFilter(pid,change.getText(),true,false));
});
cell.setComponent(filterField);
}
Whenever I use the date filter, nothing works?
Beginning:
After Selecting Date:
I tested the output of filterFormat.format(filterDate.getValue()) with a system.out.Println() and it says "11-02-2016"
However, just using a regular old textfield (not datefield) it works pretty good, I just need a leading zero on my day. But otherwise, it will filter! But I would really like to add a datefilter.
I am pretty bad at coding so any suggestions are welcome.
Date is not a String. I recommend thus to use Compare class for filtering, e.g. Compare.Greater(...), Compare.LessOrEqual(...) etc.