AbstractSelect's bound property's value is overwritten with null

Hi all,

I am currently struggling with a problem I face when I update the data source container (DSCON) (custom built, implements Container.Indexed, Container.ItemSetChangeNotifier, Property.ValueChangeNotifier) that backs a Select component.

The container itself is backed by an external datasource (EXTDS), which also stores the currently selected element (EXTSEL). This selected element value is wrapped in a custom Property (DSPROP) implementation and this implementation is set as the Select control’s propertyDataSource, so that every selection will be written directly into this value field. The itemIds are Strings and the generated items from DSCON are instances of a custom Item implementation which correctly implements hashCode() and equals().

The scenario that poses a problem is this: I have an external “trigger” to update the Select component’s elements. Here is what happens:

  • the external event triggers an update of EXTDS.
  • EXTSEL is checked to see if the selected value is still contained in EXTDS’s data. If not, EXTSEL is changed to a random value of EXTDS’s data
  • After these updates are performed, I issue a refresh on DSCON, which fetches the current data from EXTDS, updates its internal itemIds and fires an itemSetChangedEvent
  • After that I refresh DSPROP, meaning that I request it to issue a valueChangeEvent (my motivation is that the Select component asks for the updated selected itemId using getValue())
    In my scenario, the Select component now has the focus, the correct value is displayed BUT is not connected to the “real item” (which I can see when opening up the Select box - the relevant entry is not highlighted).

Unfortunately, the next time the focus moves from the Select component a valueChange event is fired, even if I did not change the value. The propagated value is null and I don’t have a clue why. I do have an idea though, but I don’t know if my suspicion is correct. I debugged my application and ended up in Select’s changeVariables() method. There I found the following line (420 in Vaadin 6.4.4):

final Object id = itemIdMapper.get(ka[0]
);

ka[0]
contains a numeric value that is not present in the itemIdMapper (it usually is off by one), so id will be null. ka[0]
seems to be the value of the previously selected item, but I don’t understand why this value is triggered now, because I requested the component to update its selection (by issuing the valueChangeEvent on the property) before returning to the client.

I am stuck here and may miss something obvious, but I don’t know where that old selection id is coming from. I also suspect that the old selection id is the reason why a valueChangeEvent is emitted from the Select component even if I don’t really change the value myself (the focus-loss seems to trigger this as the component is set to be in immediate mode)

Thanks in advance

Sven

Hi,

I did not notice any obvious cause by just by reading trough your description, but I did notice this potential gotcha:

Is the external event triggered outside the request/response, so that it’s not the users actions that causes the update, but in effect a different thread? If so, does it synchronize on the application instance(s)?
Problems that this could cause are usually more timing-sensitive and not so easily repeatable as your problem seems to be, but let’s just rule out this cause first :slight_smile:

Best Regards,
Marc

Hi Marc,

the external trigger works like this:

  • I have a TextField that is bound to a property (a custom property that wraps some kind of bean)
  • whenever the property is changed (i.e. the user changes the text in the TextField), I write the value into the bean (in the setValue() method).
  • changing the bean’s value fires an event that is caught by a listener who in turn is responsible to update the Select field (based on the provided text, the selection has to change)

So basically all the processing (incl. updating the Select’s datasource and updating the property’s backing value in the Select control) takes place when the valueChangeEvent from the TextField is processed by my custom property.

This problem is still unsolved and I am slowly running out of ideas. I don’t know if I make a mistake concerning the usage of properties and data sources or if this is a bug in Vaadin…

If you could post a test case it would certainly be easier to figure out what is wrong. At least I am not able to figure out what could possibly go wrong just by reading the description on what is being done.

After attending Devoxx and having a talk with Teemo I finally managed to create a stripped-down version of the app I am developing (please bear in mind that this example is taken out of a larger app thus it is a bit complex).

Here is what you can do to test the behaviour:

  • run the app
  • check the list value - it is foo and if you open the list you see that foo is selected in the contained list as well
  • change the value in the text field to “special”. This triggers a change of the list to a list with only one entry (“foo”)
  • then click on the drop down arrow - a “null” selection event is propagated to the underlying property and “foo”, although contained in the list, is not selected
  • close the dropdown without doing anything and open it again - a new valuechangeevent is fired, this time with value “foo” and then foo is also selected in the list

Note: All the list-changing stuff is happening in the MainApplication class.
11506.zip (9.36 KB)

Created a ticket for this issue: http://dev.vaadin.com/ticket/6170

There seems to be a problem in some cases with a ComboBox when the data source is changed and the new data source contains the previously selected value.

Just wanted to drop in and report that I checked Vaadin 6.5.0 and the bug is fixed for me and everything seems to work like a charm! Thanks so much!