[ https://issues.apache.org/jira/browse/FLEX-16418?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justin Mclean updated FLEX-16418: --------------------------------- Labels: easyfix easytest (was: ) > ComboBase selectItem leads to error with empty dataProvider > ----------------------------------------------------------- > > Key: FLEX-16418 > URL: https://issues.apache.org/jira/browse/FLEX-16418 > Project: Apache Flex > Issue Type: Bug > Components: mx: ComboBox > Affects Versions: Adobe Flex SDK 3.1 (Release) > Environment: Affected OS(s): All OS Platforms > Affected OS(s): All OS Platforms > Language Found: English > Reporter: Adobe JIRA > Labels: easyfix, easytest > > Steps to reproduce: > 1. Create ComboBox. It's dataProvider is ArrayCollection with filterFunction. > Filter Function is very simple - it's check items and return only those which > identities are positive. > In example: > dataProvider [{identity: 1}, {identity: -1}, {identity: -2}, {identity: -3}] > 2. Then we add event listener on this ArrayCollection, which will check for > COLLECTION_CHANGE event and re-select first positive number (In our cases) > 3. Set selectedItem to {identity: 1} > 4. Remove {identity: 1} item from dataProvider. After that CollectionChange > handler function will be executed, and it tries to set null into selectedItem > (which in that moment is {identity: 1}) > > Actual Results: > Fails with exception: > ReferenceError: Error #1069: Property data not found on Object and there is > no default value. > at mx.controls::ComboBase/get > value()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBase.as:880] > at > mx.controls::ComboBase/setSelectedItem()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBase.as:717] > at mx.controls::ComboBase/set > selectedItem()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBase.as:706] > at mx.controls::ComboBox/set > selectedItem()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBox.as:842] > at > mx.controls::ComboBase/updateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBase.as:1211] > at > mx.controls::ComboBox/updateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\ComboBox.as:1208] > at > mx.core::UIComponent/validateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6293] > at > mx.managers::LayoutManager/validateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:605] > at > mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:678] > at Function/http://adobe.com/AS3/2006/builtin::apply() > > Expected Results: > Should work > > Workaround (if any): > > In mx.controls.ComboBase I've found method > public function get value():Object > { > if (_editable) > return text; > var item:Object = selectedItem; > if (item == null || typeof(item) != "object") > return item; > // Note: the explicit comparison with null is important, because > otherwise when > // the data is zero, the label will be returned. See bug 183294 for > an example. > return item.data != null ? item.data : item.label; > } > As you notice my {identity: 1} item has no properties "data" and "label" and > function crashed in this lines. Maybe it will be right to make like this: > if (item.hasOwnProperty("data") && item.data!=null) > return item.data; > if (item.hasOwnProperty(labelField) && item.labelField!=null) > return item[labelField]; > if (item.hasOwnProperty("label") &7 item.label!=null) > return item.label; > And another method > private function setSelectedItem(data:Object, clearFirst:Boolean = > true):void > { > //2 code paths: one for before collection, one after > if (!collection || collection.length == 0) > { > _selectedItem = value; > selectedItemChanged = true; > invalidateDisplayList(); > return; > } > ... > } > My collection (it's dataProvider) is empty, that's why this methods tries to > make: _selectedItem = value; > I think this is mistake in this method, because setSelectedItem has two > arguments "data" and "clearFirst". There is no "value" argument. Maybe you > should use "data" instead of value in that case. Because value is a getter > function which cause the problem i've described earlier. > return item; -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira