3 Replies Latest reply on Mar 10, 2010 3:46 AM by Karl_Sigiscar_1971

    data between mxml components

    hansvdzijl

      I have a question about data between mxml components.
      Product.mxml is the overview screen for the products and ProductDetail.mxml (it is a TitleWindow) the detail screen.
      In the Product I define a value object ProductVo with all the data. When I click a record in the overview and click the button 'change' (changeProduct function) then a popup window appears with all the data in it.

       

      Code in Product.mxml:
      [Bindable]
      public var myWin:ProductDatail;

       

      private function changeProduct():void {
        myWin = PopUpManager.createPopUp(this, ProductDetail, true) as ProductDetail;
        myWin["btnSave"].addEventListener("click", save);
      }

       

      private function save(event:Event):void {
        productVo.productId = myWin.ti_productnr.text;
        productVo.name = myWin.ti_name.text;
        productVo.ean = myWin.ti_ean.text;

       

        ...some code to save the data in the db...
      }

       

      Code in ProductDetail.mxml:
      [Bindable]
      public var productDetailVo:ProductVo;

       

          <mx:Form>
              <mx:FormItem label="Productnr" required="true">
                  <mx:TextInput id="ti_productnr" text="{productDetailVo.productId}" width="60"/>
              </mx:FormItem>
              <mx:FormItem label="Naam" required="true">
                  <mx:TextInput id="ti_name" text="{productDetailVo.name}" width="200"/>
              </mx:FormItem>
              <mx:FormItem label="Ean">
                  <mx:TextInput id="ti_ean" text="{productDetailVo.ean}" width="100"/>
              </mx:FormItem>
             
              <mx:FormItem direction="horizontal">
                  <mx:Button id="btnSave" label="Save"/>
              </mx:FormItem>
          </mx:Form>

       

      So my question: the save function in Product.mxml, is it possible to do this in a easier way instead of linking all the data from the form into the value object? Something like productVo = myWin.productDetailVo, but that does not work.

        • 1. Re: data between mxml components
          Karl_Sigiscar_1971 Level 3

          Hi,

           

          Yes, if you use an architectural framework(e.g Cairngorm, Parsley, PureMVC...), you would have ProductVo in a model and Save would be implemented as a Command.

           

          An event to trigger a command can be dispatched from anywhere, including a popup window.

           

          Best regards,

          Karl.

          • 2. Re: data between mxml components
            hansvdzijl Level 1

            I just looked at the parsley framework and saw this code:

            private function save():void

            {
            contact.firstName = firstName.text;
            contact.lastName = lastName.text;
            contact.email = email.text;
            service.save(contact);
            }

            So, it is doing the same thing I'm doing.
            I'm using Spring and hibernate on the server level, it is my own framework.


            • 3. Re: data between mxml components
              Karl_Sigiscar_1971 Level 3

              Yes, but in the case of Parsley, you could have save be the handler for a command execution (I renamed save to execute as it's now in a command, although you could keep the name if you want):

               

              [Command]

              public function execute(event:SaveEvent):AsyncToken

              {

              }


              The SaveEvent class would have a property of type ProductVO in which you pass all the details of the product from the controls in your popup.