Cache problem in ComboBox continues

[font=Verdana]
Hi all,

It seems like, the caching problem of ComboBox goes on.
The one which is described in this thread :
http://vaadin.com/forum/-/message_boards/message/151590

It says
this ticket
solved the problem, but i still experience it (using 6.4.5)

I’ve 2 combos. One is for city, other for region. Region combo is tied to a Form through a FieldWrapper.

Although i change the city selection, the
previously selected region
still appears as selected, although it is no longer valid.

Here is the code for FieldWrapper


public class RegionField extends FieldWrapper<Region> {

    private BeanItemContainer<Region> regionContainer;
    private BeanItemContainer<City> cityContainer;
    private List<Region> regions;

    public RegionField(final List<Region> regions) {
        // no conversions
        super(new ComboBox("Select Region"), null, Region.class);
        this.regions = regions;

        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(false);
        layout.setSpacing(true);

        final ComboBox cityCombo = new ComboBox("Select City", getCityContainer());
        cityCombo.setNullSelectionAllowed(false);
        cityCombo.setImmediate(true);
        layout.addComponent(cityCombo);

        final ComboBox regionCombo = (ComboBox) getWrappedField();
        regionCombo.setNullSelectionAllowed(false);
        regionCombo.setImmediate(true);
        regionCombo.setContainerDataSource(getRegionContainer());
        regionCombo.setItemCaptionPropertyId("name");
        layout.addComponent(regionCombo);

        cityCombo.addListener(new Property.ValueChangeListener() {
            public void valueChange(Property.ValueChangeEvent event) {
                getRegionContainer().removeAllContainerFilters();
                getRegionContainer().addContainerFilter("city", event.getProperty().getValue().toString(), true, true);
            }
        });

        setCompositionRoot(layout);
    }


    protected BeanItemContainer<Region> getRegionContainer() {
        if (regionContainer == null) {
            regionContainer = new BeanItemContainer<Region>(Region.class);
            for (Region region : regions) {
                regionContainer.addBean(region);
            }
        }
        return regionContainer;
    }

    protected BeanItemContainer<City> getCityContainer() {
        if (cityContainer == null) {
            cityContainer = new BeanItemContainer<City>(City.class);
            for (Region region : regions) {
                cityContainer.addBean(region.getCity());
            }
        }
        return cityContainer;
    }
}

Btw, I’m new to Vaadin. I’ve used most of the alternative web frameworks, and i love the idea behind Vaadin. I believe this is the way to go. But, it has been 4 days of trial and unfortunately i’m having difficulties even with basics(like the problem above). This makes me suspicious about its maturity. I know, it is too early to say anything but i thought i could get on board faster-as it is not hard to understand the underlying architecture-. I sincerely hope, it just needs some more time to learn how to use correctly.

[/font]

Hi,

I guess you are actually facing this issue: http://dev.vaadin.com/ticket/3566 instead of the ticket you referred. Too bad I have closed it as wontfix. The Container.Filterable api that you are using in your value change listener is bit problematic in various places like in ComboBox. We can’t build a validity check for the ComboBox on each filter change.

You could solve the issue in two ways:

  1. Populate the region container based the city in the value change listener (practically doing the filtering manually and not to use the Container.Filteraable API at all).

  2. Check that the value is valid after the container has been filtered.

I’d go with the option 1. You’d get some more control on what is actually happening and the filtering code would actually become more readable and type safe than what it is in you code (admitted that it might be bit longer that the one liner in your code snippet).

cheers,
matti

Hi Matti,

I used the first option and it works well. Thank you