Flex is hard (or possibly I'm stupid)


ok, i've been trying wrap head around flex/actionscript several weeks now.  45 year old brain hurts.  here's am.  have datagrid populated via coldfuison component via flashremoting.  have form add new item database (lost ton of hair on one...couldn't 'get' idea had create instance of class, assign new values , pass object coldfusion cfc...but eventually, sunk in)...got form grow , shrink...and pretty sure can pretty validation , nice transitions.  however, having real trouble editing records datagrid.

 

i want populate form row datagrid when user clicks on row...and seems easy if form text fields, alas, 4 of them combo boxes...plus in form, combo boxes populated 4 separate remoteobject calls database...so how set selected value reflect on datagrid row...the text boxes seem pretty simple...but no matter try, can't value show correctly in comboboxes.  can combobox blank, or [object,object] or reflect no change...

 

so, below code...the function want populate form is:   private function edititeminserthandler().  i'd appreciate understranding what's going on/wrong.

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical" applicationcomplete="init()">
    <mx:label text="database of estimate items" fontsize="18">
       
    </mx:label>
   
    <mx:script>
    <![cdata[
        import mx.rpc.events.resultevent;
        import mx.collections.arraycollection;
//the following vars remote object tags below
        [bindable]
        private var acestimatesfixeditems:arraycollection;
        [bindable]
        private var acjobtype:arraycollection;
        [bindable]
        private var acconstructionphases:arraycollection;
        [bindable]
        private var acitemtype:arraycollection;
        [bindable]
        private var acdefaultunittype:arraycollection;
       
        private var estimateitem:estimatesfixeditems;
   
       
//at start-up
    private function init():void
    {
        estimatesfixeditemsgateway.getall();
        jobesttypegateway.getall();
        contructionphasesgateway.getall();
        itemtypegateway.getall();
        defaultunittypegateway.getall();
    }
       
               
//the following functions handling result events remote objects
        private function resulthandler(event:resultevent):void
        {
            acestimatesfixeditems = new arraycollection(
            event.result array)
        }
        private function jobtyperesulthandler(event:resultevent):void
        {
            acjobtype = new arraycollection(
            event.result array)
        }
        private function constructionphasesresulthandler(event:resultevent):void
        {
            acconstructionphases = new arraycollection(
            event.result array)
        }
       
        private function itemtyperesulthandler(event:resultevent):void
        {
            acitemtype = new arraycollection(
            event.result array)
        }
       
        private function defaultunittyperesulthandler(event:resultevent):void
        {
            acdefaultunittype = new arraycollection(
            event.result array)
        }
       
        private function openaddform():void
        {
            addform.height = 250;
            addform.width = 700;
        }
       
//called when item clicked in datagrid       
        private function edititeminserthandler():void
        {
            openaddform();
            addedititem.label = "edit";
            constructionph.selecteditem.constructionphaseid = dg.selecteditem.constructionphase;
           
            constructionph.selecteditem = dg.selecteditem.constructionphase;
           
            itemname.text = dg.selecteditem.itemname;
        }
       
        private function addedititeminserthandler():void
        {
            var dataestimatefixeditem:estimatesfixeditems = new estimatesfixeditems();
               
               
               
                dataestimatefixeditem.constructionphase = constructionph.selecteditem.constructionphaseid;
                dataestimatefixeditem.jobestimatetype = jobestimatetype.selecteditem.jobtypeid;
                dataestimatefixeditem.itemtype = itemtype.selecteditem.itemtypeid;
                dataestimatefixeditem.defaultunittype = defaultunittype.selecteditem.defaultunittypeid;
                dataestimatefixeditem.itemname = itemname.text;
                dataestimatefixeditem.itemdescription= itemdescription.text;
                //dataestimatefixeditem.priceperunit = priceperunit.text;
               
       
            estimatesfixeditemsgateway.save(dataestimatefixeditem);
            addform.height = 5;
           
           
        }
        private function addedititemresulthandler():void
        {
           
        }
       
       
               
    ]]>
</mx:script>

 

<mx:remoteobject id="jobesttypegateway" destination="coldfusion"
    source="estimate.cfcs.jobesttypegateway"   showbusycursor="true">
    <mx:method name="getall" result="jobtyperesulthandler(event)"/>
    <mx:method name="save" result="addedititemresulthandler()"/>

 

</mx:remoteobject>
<mx:remoteobject id="contructionphasesgateway" destination="coldfusion"
     source="estimate.cfcs.constructionphasesgateway" result="constructionphasesresulthandler(event)"
      showbusycursor="true"/>
<mx:remoteobject id="estimatesfixeditemsgateway" destination="coldfusion"
      source="estimate.cfcs.estimatesfixeditemsgateway" result="resulthandler(event)"
        showbusycursor="true"/>
<mx:remoteobject id="itemtypegateway" destination="coldfusion"
         source="estimate.cfcs.itemtypegateway" result="itemtyperesulthandler(event)"
          showbusycursor="true"/>
<mx:remoteobject id="defaultunittypegateway" destination="coldfusion"
         source="estimate.cfcs.defaultunittypegateway" result="defaultunittyperesulthandler(event)"
          showbusycursor="true"/>
   
<mx:panel>

 

<mx:panel title="to edit or delete item, double click item." height="75%" width="100%"
        paddingtop="10" paddingleft="10" paddingright="10" paddingbottom="10">
<mx:hbox>
    <mx:button id="addedit" click="openaddform()" label="add new item database"/>
    <mx:button id="refresh" click="openaddform()" label="refresh database view"/>
</mx:hbox>
</mx:panel>

 

<mx:form  id="addform"  height="10">
    <mx:formheading id="addformlabel" label="add new item database."/>
        <mx:hbox>
            <mx:formitem label="job type">
                 <mx:combobox id="jobestimatetype" dataprovider="{acjobtype}" labelfield="jobtype"/>
            </mx:formitem>
            <mx:formitem label="job phase">
                <mx:combobox id="constructionph"  dataprovider="{acconstructionphases}" labelfield="constructionphasedes"/>
            </mx:formitem>
        </mx:hbox>
        <mx:hbox>
            <mx:formitem label="item type">
                <mx:combobox id="itemtype" dataprovider="{acitemtype}"  labelfield="itemtypedes"/>
            </mx:formitem>
            <mx:formitem label="default unit type">
                <mx:combobox id="defaultunittype"  dataprovider="{acdefaultunittype}" labelfield="defaultunittypedes"/>
            </mx:formitem>
        </mx:hbox>
        <mx:hbox>
            <mx:formitem label="item title">
                <mx:textinput id="itemname"/>                     
            </mx:formitem>
            <mx:formitem label="description">
                <mx:textarea id="itemdescription"/>
            </mx:formitem>
        </mx:hbox>
        <mx:formitem label="price per unit">
            <mx:textinput id="priceperunit" width="40"/>
        </mx:formitem>
        <mx:formitem>
            <mx:button id="addedititem" label="add" click="addedititeminserthandler()"/>
        </mx:formitem>
   
   
</mx:form>

 

 

 

<mx:datagrid id="dg" dataprovider="{acestimatesfixeditems}" variablerowheight="true" click="edititeminserthandler()">
    <mx:columns>
        <mx:datagridcolumn headertext="job type" datafield="jobtype"/>
        <mx:datagridcolumn headertext="job phase" datafield="constructionphasedes"/>
        <mx:datagridcolumn headertext="item type" datafield="itemtypedes"/>
         <mx:datagridcolumn headertext="item name" datafield="itemname" />
         <mx:datagridcolumn headertext="description" width="200" wordwrap="true"
              datafield="itemdescription" />
           <mx:datagridcolumn headertext="unit" datafield="defaultunittypedes" width="50"/>
           <mx:datagridcolumn headertext="price" datafield="priceperunit" width="50"/>
      </mx:columns>

 

</mx:datagrid>
    
</mx:panel>

 

 

 

</mx:application>

loop through dataprovider , find index of selected item bind index selectedindex property in combobox display selected item. if getting [object object] displayed, check labelfield property of cb.



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???