PDA

View Full Version : [2.2.5] ComboBox getValue() issue when not rendered and with force selection set



Arnaud Forcinal
17 Oct 2011, 4:37 AM
I have discovered an issue with ComboBox in Ext GWT 2.2.5.

The context:
I have a ComboBox that is not rendered (it is rendered for some users, and not rendered for others, but it's always part of the form). This ComboBox is linked to a store backed by a loader/proxy and the force selection attribute is set.

Behavior in Ext GWT 2.2.4:
setValue() is called to set the combobox value and getValue() is returning this value.

Behavior in Ext GWT 2.2.5:
setValue() is called to set the combobox value and getValue() is returning null.

Analysis:
When the setValue() is called, a blur event is fired on the ComboBox and the triggerBlur() method is executed. This method then calls doForce(). The new behavior of doForce() is to try to initialize the box list if the initialized flag is not set and this sets the initialize flag.
After that the getValue() call doesn't exit with the stored value as the initialized flag is set but instead tries to get the available values from the store and match the stored value with those. This does not work because if the store is backed by a loader/proxy it won't have any value before the doQuery method is called to load the store. As the ComboBox is not rendered, the doQuery method is not called and the store has no values. The getValue() method then returns null.
I think the issue is that the doForce() method should not have the side-effect of setting the initialized flag.

Regards,

sven
17 Oct 2011, 6:15 AM
Before the behaviour was completely different if it was initialized or not. This was a bug and was fixed.

Now it behaves exactly the same in both cases. getValue will always look at the input field and tries to find the value in the store. If that cannot be found, it returns null.

You could override that behaviour so if the input field value matches the old value of the combobox, it would directly return that instead of going over the propertyeditor.

sven
17 Oct 2011, 6:27 AM
private class MyCombo<M extends ModelData> extends ComboBox<M> { @Override
public M getValue() {
if (value != null) {
Object val = value.get(getDisplayField());
if (getRawValue().equals(val != null ? val.toString() : null)) {
return value;
}


}
return super.getValue();
}
}

I have not tested this change, but it could solve the issue you have and could be the behaviour you are looking for.

Arnaud Forcinal
17 Oct 2011, 7:00 AM
I forgot to say that we also found a way to have the behavior we were looking for: we forced the load of the store during its construction to ensure the propertyeditor will work correctly. (this was made possible by the fact it was linked to a MemoryProxy without RPC calls to be made)

I understand that the behavior of the ComboBox has to be consistent but it's unsettling to set a value in the combo and to retrieve the correct value if the combo is rendered or null if not rendered. Maybe getValue should exit early if the rendered property is not set?

sven
17 Oct 2011, 8:25 AM
The behaviour is not if its rendered or not rendered. If the value is not in the store, it should return null, as the value cannot be matched to something in the store. The patch i posted here above changes this behaviour.