You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a Map as the items values for an OptionWriter-based tag and ommiting the itemValue property (valueProperty is null), OptionWriter still creates BeanWrappers around the map key and values although they are never used.
As a result of that, one is unable to use null as a map key, which may be useful for instance when the map contains enum values as keys and their localized names as values. In this scenario, it may be useful to include null as a map key which represents an empty field value.
We'll also have to make the mapKey.toString() and mapValue.toString() code null-safe then, since that would be executed instead of the BeanWrapper calls... I suppose you would rather expect null to turn into an empty String there, i.e. not into "null" or the like?
Definitely. As I said, my use case is enums as map keys and their localized names (via a message source) as map values. Such a field is bound to an enum field on the model attribute, so an empty string in the option values should be translated to a null enum value. I hope that the property editor already does that...
I've adapted this for 3.0.2 now. This will be available in tonight's 3.0.2 snapshot - feel free to give it an early try if you chance, and let me know whether it works for you.
Shai Yallin opened SPR-7024 and commented
When using a Map as the items values for an OptionWriter-based tag and ommiting the itemValue property (valueProperty is null), OptionWriter still creates BeanWrappers around the map key and values although they are never used.
As a result of that, one is unable to use null as a map key, which may be useful for instance when the map contains enum values as keys and their localized names as values. In this scenario, it may be useful to include null as a map key which represents an empty field value.
affected code:
{{
Object mapKey = entry.getKey();
Object mapValue = entry.getValue();
BeanWrapper mapKeyWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapKey);
BeanWrapper mapValueWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapValue);
Object renderValue = (this.valueProperty != null ? mapKeyWrapper.getPropertyValue(this.valueProperty) :
mapKey.toString());
Object renderLabel = (this.labelProperty != null ? mapValueWrapper.getPropertyValue(this.labelProperty) :
mapValue.toString());
renderOption(tagWriter, mapKey, renderValue, renderLabel);
}}
fix suggestion: only create the wrappers if this.valueProperty != null
Affects: 3.0.1
Referenced from: commits a614430
The text was updated successfully, but these errors were encountered: