2 Replies Latest reply on Jun 23, 2011 6:42 AM by UbuntuPenguin

    Itemeditor with combobox throws TypeError

    RonaldKamp

      Hi,

       

      I'm a junior developer at Ordina Belgium. I'm currently working on a project in flex. I need to have a datagrid, where the values are shown as strings. When the user selects a certain row, the row changes and shows some comboboxes. when the user selects a certain value in the combobox, the value is saved correctly, but when I try to exit the itemeditor, the following error is thrown:

       

      TypeError: Error #1034: Type Coercion failed: cannot convert "Classic Line" to com.bgc.dto.Product.

       

      Here is my code:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init()"

         xmlns:view="com.bgc.view.*" >

           <mx:Script>

                     <![CDATA[

                             private var presenter:OrderActionListsPresenter;

       

      [Bindable]

      private var categoriesNames:ArrayCollection;

      [Bindable]

      private var packStructures:ArrayCollection = new ArrayCollection();

      [Bindable]

      public static var actions:ArrayCollection = new ArrayCollection();

      [Bindable]

      public var productsPerCategory:ArrayCollection;

      [Bindable]

      public static var selectedProducts:ArrayCollection = new ArrayCollection();

      [Bindable]

      public var orderActionsPerMapping:ArrayCollection;

       

       

      private function init():void{

      this.presenter = new OrderActionListsPresenter(this);

      presenter.getStartupData();

       

       

      packStructures.addItem("DP");

      packStructures.addItem("E2E");

       

       

      this.orderActionsPerMapping = new ArrayCollection();

      var orderActionEmpty:OrderAction = new OrderAction();

      orderActionsPerMapping.addItem(orderActionEmpty);

       

      }

       

      public function checkOrderAction(data:*):void{

      var order:OrderAction = data as OrderAction;

      if(order.action != null && order.affectedProduct != null){

      var newOrderAction:OrderAction = new OrderAction();

      orderActionsPerMapping.addItem(newOrderAction);

      }

      }

       

       

      protected function cboProductCat_changeHandler(event:ListEvent):void

      {

      var selectedItem:String = (event.target as ComboBox).selectedItem as String;

      if(selectedItem != "<Click to select category>"){

      presenter.getProductsForCategory(selectedItem);

      }

      }

       

       

      protected function cboProduct_changeHandler(event:ListEvent):void

      {

      OrderActionListManager.selectedProducts.removeAll();

       

      var fromProd:Product = cboFromProduct.selectedItem as Product;

      var toProd:Product = cboToProduct.selectedItem as Product;

       

      if(fromProd != null &&  fromProd.prodName != "None") OrderActionListManager.selectedProducts.addItem(fromProd);

      if(toProd != null && toProd.prodName != "None") OrderActionListManager.selectedProducts.addItem(toProd);

      (OrderActionListManager.selectedProducts.length == 2) ? grdMappings.enabled = true : grdMappings.enabled = false;

      }

       

       

      public function getProductLabel(item:Object,column:DataGridColumn):String

      {

      if((item as OrderAction).affectedProduct != null){

      return (item[column.dataField] as Product).prodName;

      }

      return "";

      }

                     ]]>

                </mx:Script>

       

      <mx:DataGrid id="grdMappings" width="500" editable="true" dataProvider="{orderActionsPerMapping}" enabled="false" >

           <mx:columns>

                <mx:DataGridColumn id="clmOrderAction" width="250" headerText="Action" dataField="action">

                     <mx:itemEditor>

                          <mx:Component>

                               <mx:ComboBox dataProvider="{OrderActionListManager.actions}" change="cboActions_changeHandler(event)">

                                    <mx:Script>

                                         <![CDATA[

                                              import com.bgc.dto.OrderAction;

                                              import mx.events.ListEvent;

       

                                              protected function cboActions_changeHandler(event:ListEvent):void

                                              {

      var order:OrderAction = data as OrderAction;

      order.action = (event.target as ComboBox).selectedItem as String;

      outerDocument.checkOrderAction(order);

        }

           ]]>

                                    </mx:Script>

                               </mx:ComboBox>

                          </mx:Component>

                     </mx:itemEditor>

      </mx:DataGridColumn>

      <mx:DataGridColumn id="clmAffectedProduct" width="250" headerText="Affected product" dataField="affectedProduct" labelFunction="getProductLabel">

           <mx:itemEditor>

                <mx:Component>

                     <mx:ComboBox dataProvider="{OrderActionListManager.selectedProducts}" change="cboProduct_changeHandler(event)" labelField="prodName">

                          <mx:Script>

                               <![CDATA[

      import com.bgc.dto.OrderAction;

      import com.bgc.dto.Product;

       

      import mx.events.ListEvent;

      protected function cboProduct_changeHandler(event:ListEvent):void

      {

      var order:OrderAction = data as OrderAction;

      order.affectedProduct = (event.target as ComboBox).selectedItem as Product;

      outerDocument.checkOrderAction(order);

      }

         ]]>

           </mx:Script>

              </mx:ComboBox>

                </mx:Component>

           </mx:itemEditor>

      </mx:DataGridColumn>

       

      Does anyone know how to fix this?

       

      Thanks in advance for your answers .

       

      Kind regards,

       

      Ronald Kamp,

      Junior Java developer at Ordina Belgium

        • 1. Re: Itemeditor with combobox throws TypeError
          UbuntuPenguin Level 4

          That means that somewhere you are trying to stuff "Classic Line" into a variable or function that is declared to be a product.  Is "Classic Line" the string you put into the text editor when it choked ?

          • 2. Re: Itemeditor with combobox throws TypeError
            RonaldKamp Level 1

            Classic Line is the one that I selected in the drop down list. Somehow, I think that it doesn't interpret the itemeditor the way it is supposed to.

             

            I removed the item editor with the combobox. This way, it would show my product name. when I click this, it shows a text editor and when I try to exit this one, it throws the same error. So somehow, I think it opens an item editor twice, one with a combobox and one with the text editor.

             

            If you know a way to prevent this, please let me know.

             

            Kind regards ,

             

            Ronald Kamp