datenhahn / componentrenderer

A ComponentRenderer for the Vaadin Grid
Apache License 2.0
6 stars 8 forks source link

ComponentPropertyGenerator should override modifyFilter(Filter filter) to support GeneratedProperty filter #27

Closed LaiZhou closed 8 years ago

LaiZhou commented 8 years ago

when call grid.addComponentColumn, the property is a generated property. when add filter of this property,like:

HeaderCell cell = filterRow.getCell(pid);
            // Have an input field to use for filter
            TextField filterField = new TextField();
            filterField.setColumns(grid.getColumns().size());
            // Update filter When the filter input is changed
            filterField.addTextChangeListener(change -> {
                // Can't modify filters so need to replace
                GeneratedPropertyContainer container = (GeneratedPropertyContainer) grid.getContainerDataSource();
                Filter oldFilter = null;
                for (Filter filter : container.getContainerFilters()) {
                    if (filter.appliesToProperty(pid)) {
                        oldFilter = filter;
                        break;
                    }
                }
                if (oldFilter != null) {
                    container.removeContainerFilter(oldFilter);
                }
                if (!change.getText().isEmpty()) {
                    container.addContainerFilter(new SimpleStringFilter(pid, change.getText(), true, false));
                }

it throws UnsupportedFilterException ,because ComponentPropertyGenerator.java does't support modify the filter, . patch code :

@Override
    public Filter modifyFilter(Filter filter) throws UnsupportedFilterException {

        return filter;
    }
datenhahn commented 8 years ago

Hi, adding Filters on a generated Property is not a good idea, as it would have to generate all properties to apply the filter. Instead add a filter to the underlying container ( e.g. BeanItemContainer). In most cases you want to filter on that data anyway.

You see an example at the bottom of this gist:

https://gist.github.com/datenhahn/d9ecad5eba14eba1d326

LaiZhou commented 8 years ago

test your code,done. Wow, I think you're an expert on vaadin, and you are a nice guy.As I'm a green hand of vaadin,actually,I have some problems of vaadin: Server push (long polling)In my application does not work .I use the official vaddin-spring add-on ,and my app is based on springBoot,can you give me a help?

datenhahn commented 8 years ago

Vaadin like every other framework takes some time to get familiar with some framework specific special Cases, but if you use it for some time development is fun and quite produktive.

A bit more details about your problem would be helpful :) Maybe you ran into this Problem?: https://github.com/peholmst/vaadin4spring/issues/51 You can also check if maybe polling is an Option for you. Polling just works and is easy to enable since vaadin 7. https://vaadin.com/wiki/-/wiki/Main/Using+polling

If you use push be sure to sync access to the ui. See access ui from a different thread Here: https://vaadin.com/docs/-/part/framework/advanced/advanced-push.html

LaiZhou commented 8 years ago

After dig the code of vaadin framework, I found a bug about push (to be verified), here is it: https://vaadin.com/forum#!/thread/13579011 Thank you anyway. Now I 'd close this issue.May be we can discuss more about vaadin, Would you like me to send you an e-mail discussion or how can I contact you online?( I'm a developer from China.)