FilteringTable add-on

Hi!

Thank you for providing the plugin with the Serialized class!

Unfortunately I have a lot of Exceptions when I want to filter columns with integers in it.

com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in org.tepi.filtertable.numberfilter.NumberFilterPopup$2 failed.

Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method valueChange in org.tepi.filtertable.FilterFieldGenerator$2 failed.

Caused by: java.lang.RuntimeException: Creating number filter has failed.

Caused by: java.lang.NoSuchMethodException: int.valueOf(java.lang.String)

There seems to be a problem in the standard filter that is used.

It would be very nice if you could fix the problem or give a quick workaround :slight_smile:

EDIT: Another question: Is it possible to turn off the new “greater than”, “smaller than” and “equals” button and get back the old textfield?

Thank you!

Hi,

could you share the relevant code? If you look at the
demo application
, the column named ‘id’ is of type Integer and the popup-style filtering works correctly. I’ll look into providing the previous functionality also.

Thanks for the feedback!

-tepi

Dear Tepi!

Thank you for the quick reply!

I used the plugin with only little modifications in the TableFilterDecorator and TableFilterGenerator classes.
So I will show you my implementation:

TableFilterDecorator:


public class TableFilterDecorator implements FilterDecorator, Serializable {

	@Override
	public String getEnumFilterDisplayName(Object propertyId, Object value) {
		return null;
	}

	@Override
	public Resource getEnumFilterIcon(Object propertyId, Object value) {
		return null;
	}

	@Override
	public String getBooleanFilterDisplayName(Object propertyId, boolean value) {
		return null;
	}

	@Override
	public Resource getBooleanFilterIcon(Object propertyId, boolean value) {
		return null;
	}

	@Override
	public String getFromCaption() {
		return "Startdatum:";
	}

	@Override
	public String getToCaption() {
		return "Enddatum:";
	}

	@Override
	public String getSetCaption() {
		// return null = use default caption
		return "Los!";
	}

	@Override
	public String getClearCaption() {
		// return null = use default caption
		return "Löschen";
	}

	@Override
	public boolean isTextFilterImmediate(Object propertyId) {
		return true;
	}

	@Override
	public int getTextChangeTimeout(Object propertyId) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getDateFieldResolution(Object propertyId) {
		return 4;
	}

	@Override
	public DateFormat getDateFormat(Object propertyId) {
		return null;
	}

	@Override
	public String getAllItemsVisibleString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public NumberFilterPopupConfig getNumberFilterPopupConfig() {
		
		NumberFilterPopupConfig config = new NumberFilterPopupConfig();
		config.setEqPrompt("gleich");
		config.setGtPrompt("größer");
		config.setLtPrompt("kleiner");
		config.setOkCaption("Los!");
		config.setResetCaption("Löschen");
		
		return config;
	}
}

TableFilterGenerator:


public class TableFilterGenerator implements FilterGenerator, Serializable {

	@Override
	public Filter generateFilter(Object propertyId, Object value) {
		// For other properties, use the default filter
		return null;
	}

	@Override
	public AbstractField getCustomFilterComponent(Object propertyId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void filterRemoved(Object propertyId) {
		// TODO Auto-generated method stub	
	}

	@Override
	public void filterAdded(Object propertyId, Class<? extends Filter> filterType, Object value) {
		// TODO Auto-generated method stub
		
	}
}

And here is the use in my table:


public class PatientBrowserList extends FilterTable {

	public PatientBrowserList() {
		
		// number of rows in the table
		setPageLength(20);

		// some UI settings
		setSelectable(true);
		setWidth("100%");
		
		// FilterTable related stuff
		setFilterDecorator(new TableFilterDecorator());
		setFilterGenerator(new TableFilterGenerator());
		setFilterBarVisible(true);
	}

Thank you very much!
Jens

Hi,

I copied your code directly from your post and could not produce any exceptions. What you left out though is what kind of container you have and what it contains when the issue is present. I just created a dummy IndexedContainer with some Integer, String and Date properties. If you still have this problem, please also provide info on your container and I might just get the issue reproduced.

-tepi

Hi Tepi!

I use a Java class from where a BeanItemContainer is created and attached to the table.
The following code shows the relevant variables that are crashing:


public class Patient extends DatabaseObject {

	protected int patientID;
	protected int patientIDSap = 0;

	public int getPatientID() {
		return patientID;
	}

	public void setPatientID(int patientID) {
		this.patientID = patientID;
	}

	public int getPatientIDSap() {
		return patientIDSap;
	}

	public void setPatientIDSap(int sapPatientID) {
		this.patientIDSap = sapPatientID;
	}

There is a lot of things around for the communication with the database i suppressed here,
but that are the main parts causing the problem.

The other fields for Strings and Date and so on are working perfectly.

BTW: I found another NotSerializableException, perhaps you could fix it in the next release :slight_smile:


IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.tepi.filtertable.numberfilter.NumberInterval

Jens

Hello Tepi,

I made a very small update on FilterTable.java to permit non String propertyIds for setFilterFieldValue. Please check the pull request on Github.

Thanks,
Tibi

Hi,
and thanks for noticing that! I just merged your changes and they will be included in the next bugfix-release.

-tepi

Hi,

I figured out what was wrong and it is now fixed in a new version I just uploaded to the directory, 0.7.1. Basically it was down to using basic data types in the Patient bean in your BeanItemContainer. Apparently java’s reflection does not do autoboxing so it tried to call int.valueOf which obviously does not exist.

Numerous other issues were fixed as well, more details can be found in the release notes in the add-on’s directory page.

-tepi

Hi Tepi!

Thank you very much!
I will test it immediately!

EDIT: Works like a charme :slight_smile:

And thank you for giving the possibility to disable the popup button for integers!

Thanks for the nice add-on. I’m just getting started with it and found that a NativeSelect does not work as a custom filter component on IE8 or Chrome, but it does work fine on Firefox. I put it into a stripped down test application for you to try.

Just as I was about to post this, I noticed you released v0.7.1, so I updated to it and Vaadin 6.8.5, but that didn’t help. As a last try, I switched to a Select instead of NativeSelect, and that works on all browsers! Unfortunately Select is based on a TextField which always allows users to type rather than just bringing up the limited options.


package com.example.vaadintest;

import java.util.Random;
import org.tepi.filtertable.FilterGenerator;
import org.tepi.filtertable.FilterTable;
import com.vaadin.Application;
import com.vaadin.data.Container;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.data.util.filter.Compare;
import com.vaadin.ui.*;

public class VaadinTestApplication extends Application
{
  private FilterTable filterTable;

  public void init()
  {
    Window mainWindow = new Window("VaadinTest Application");
    setMainWindow(mainWindow);

    filterTable = buildFilterTable();

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.addComponent(filterTable);
    mainLayout.setExpandRatio(filterTable, 1);

    mainWindow.setContent(mainLayout);
  }

  private FilterTable buildFilterTable()
  {
    FilterTable filterTable = new FilterTable("FilterTable Demo");
    filterTable.setSizeFull();

    filterTable.setFilterGenerator(new MyFilterGenerator());
    filterTable.setFilterBarVisible(true);
    filterTable.setSelectable(true);
    filterTable.setImmediate(true);
    filterTable.setContainerDataSource(buildContainer());
    return filterTable;
  }

  private Container buildContainer()
  {
    IndexedContainer cont = new IndexedContainer();
    cont.addContainerProperty("id", Integer.class, null);
    cont.addContainerProperty("severity", String.class, null);

    Random random = new Random();
    for (int i = 0; i < 100; i++)
    {
      cont.addItem(i);
      cont.getContainerProperty(i, "id").setValue(i);
      cont.getContainerProperty(i, "severity").setValue(random.nextBoolean() ? "WARNING" : "URGENT");
    }
    return cont;
  }

  private static class MyFilterGenerator implements FilterGenerator
  {
    public Filter generateFilter(Object propertyId, Object value)
    {
      if ("severity".equals(propertyId))
      {
        String v = (String) value;
        if (v != null && !v.isEmpty())
          return new Compare.Equal(propertyId, v);
      }
      return null;
    }

    public AbstractField getCustomFilterComponent(Object propertyId)
    {
      if ("severity".equals(propertyId))
      {
        NativeSelect box = new NativeSelect();
        box.addItem("");
        box.addItem("WARNING");
        box.addItem("URGENT");
        return box;
      }
      else
        return null;
    }

    public void filterRemoved(Object propertyId)
    {
    }

    public void filterAdded(Object propertyId, Class<? extends Filter> filterType, Object value)
    {
    }
  }
}

Hi!

Thanks for the nice test case :) I identified the issue to some CSS problems which were quite straightforward to fix. A new version with the fix (0.7.2) is now available in the Directory. As a side note, I noticed that the NativeSelect on Chrome does not look as fitting to the filter bar as it does on e.g. Firefox, but I think there’s not much that can be done about it.

-tepi

hi

im trying to make it work for a liferay portlet im working on but it fails. I put the two jar files in tomcat_home/webapps/ROOT/web-inf/lib and using the vaadin control panel, recompiled everything - it does find the jar files.

but when I open the page where I added the portlet it gives me a lot of exceptions and one if them complains about missing com.vaadin.ui.UniqueSerializable

im running liferay 6.0.X, vaddin 6.8.5 (latest as of today) and Your add-on is listed as supporting this and acutally not supporting vaadin 7+. I think the class com.vaadin.ui.UniqueSerializable is from vaadin 7, correct? is there a issue of mixing of vaadin version here or?

it seems that the com.vaadin.ui.UniqueSerializable is actually included within Vaadin 6.8.5, although it is only used by the Table component (and hence the FilteringTable also). Can you try to see inside your vaadin jar and see that the UniqueSerializable actually is there? Mine does have it (jar fetched with vaadin eclipse plugin) and seems to not create any problems.

I don’t know why is this class included in vaadin 6. Event the javadoc states the following, indicating that it would belong to V7:

 * @author Vaadin Ltd
 * @version 6.8.5
 * @since 7.0

must have misplaced the jar files somehow. After deleting, copying around a bit its working…

except I dont have a good picture of what to do or implement. It has no default behaviour? a bit naive, but I just changed my Table into a FilterTable in the hope that it would give me a textfield above all columns and then if I wrote something here it would filter based on string compare the rows that did equal.

but it does not show anything.

        table.setFilterFieldVisible("Navn", true);
        table.setFilterBarVisible(true);

I get a extra grey line below the headings and above the actual rows, but nothing where I can write anything or do anything.

I was looking at the example - its not up to date correct? The interfaces have changed, correct - at least “implements FilterGenerator” seams to have 4 methods I need to implement now, not just the one in the example. Can I leave the 3 new at returning null?

never mind found out it was due to the way I work with tables. It does not work when Im just adding Object to a table for rows even if I set the addContainerProperty on the table. I changed my code into doing a IndexedContainer and now its showing input fields and letting me filter “queals” on strings.

on to figuring out how to actually control the filtering :smiley:

Thank you Tepi. That resolved it on all my test browsers: Firefox 16/Linux, Chrome 22/Linux, IE8/WinXP, and IE9/Win7.

A little contribute back for those like me who want the filter row to take up minimal space, these styles added to the application theme shrink it down, for TextField, Select, and NativeSelect (haven’t tried others). Also, it sets the columns with no filters to blank white space. (The grey that was there doesn’t match the Runo theme.)


.filters-panel {
    background-color: #fff !important;
    height: 18px !important;
}

.filters-panel .v-label,
.filters-panel .v-select,
.filters-panel .filterplaceholder {
    height: 16px !important;
}

.v-table .filters-panel .v-textfield,
.v-table .filters-panel .v-select,
.v-table .filters-panel .v-filterselect {
    height: 13px !important;
    font-size: 11px !important;
}
.v-table .filters-panel .v-filterselect-input {
    font-size: 11px !important;
}
.v-table .filters-panel .v-select-select {
    font-size: 11px !important;
}

Tepi, would it be difficult to include source and javadoc .jar files in the releases? Each time there’s an update (three times in two days now - thank you for being so responsive!), I have to download the plug-in, then the source code, and generate the Javadoc. Surely many others are doing the same. I don’t want to burden you though - it’s very nice of you just to contribute this.

  • Adam

Hi Adam,

I just released another version :D but this time with javadocs and a separate sources jar package. Please tell me if this is close to what you wanted. The ant build script of the project will now also generate these if you want to check out the project and do it yourself.

And thanks for your styling mod, I bet a lot of users will find it usable. This addon is quite difficult in the theming respect since it integrates so heavily with an existing component, preveting me from just theming it ‘independently’. For now I’ve decided to just support/use the default (reindeer) theme to limit the amount of work I need to do with the css.

Thank you… I wasn’t expecting a new release just to put the source and javadoc in. It works well, except I still had to cd into the javadoc directory and run jar cvf ../javadoc.jar *
Eclipse doesn’t allow relative paths to a javadoc directory, but does allow a workspace path to a javadoc .jar. (I avoid absolute paths in my file system within projects files - since of course they won’t work on other people’s computers.) Other people may prefer to have it outside an archive so they can view it from a browser though.

I started using a numeric filter, so here’s the style.css additions again to shrink the vertical space used by the filters - now with number filer popup support.


/* Override styles for FilterTable to use minimal vertical space */
.filters-panel {
    background-color: #fff !important;
    height: 18px !important;
}

.filters-panel .v-label,
.filters-panel .v-select,
.filters-panel .filterplaceholder {
    height: 16px !important;
}

.v-table .filters-panel .v-textfield,
.v-table .filters-panel .v-select,
.v-table .filters-panel .v-filterselect {
    height: 13px !important;
    font-size: 11px !important;
}
.v-table .filters-panel .v-filterselect-input {
    font-size: 11px !important;
}
.v-table .filters-panel .v-select-select {
    font-size: 11px !important;
}

.numberfilterpopup {
    height: 18px !important;
    padding: 0px 6px !important;
}

.numberfilterpopup .v-button-wrap {
    border: none !important;
	height: 13px !important;
}
.numberfilterpopup .v-button-caption {
    font-size: 11px !important;
}
.v-popupbutton.numberfilterpopup .v-popup-indicator {
    height: 16px;
}

Hi, I’m facing some problems changing setVisible property of a FilterTable in a TabSheet. Please, could you investigate?

Could you add a bit more info on how to reproduce the problem? I tried both setting the Tab and the FilteringTable itself (within the tabsheet) visible/not-visible and could not notice any issues.