1 Reply Latest reply on Mar 30, 2010 5:54 AM by carstephun

    implementing Dirty Flag for a generated Model (Flex 4)

    carstephun

      Hi there,

       

      I try to implement a dirty flag for a model generated by a Data Binding Wizard. I tried several ways but always failed to get it work properly bounded to the 'enabled' property of a button. Is there a "best approach" to implement this in a by Flex 4 generated model?

       

      I have all the Form elements bound to the model's properties and defined fx:Bindings on the model's property as well to get the changes back to the model as well.

       

      -> I tried to listen to the properyChange event on the Super model but I always returned true for the Dirty flag and couldn't set it to false when I loaded the model into a Form.

      -> I tried to implement a similar approach like below, instead of doing a normal 'getter' function on the isDirty flag I bounded it to the propertyChange event, it failed exactly the same way as above

       

      I did used my own solution earlier like this:

       

      [RemoteClass(alias="VODictionaryEntry")]
           [Bindable]
           public class VODictionaryEntry
           {
                     private var _id:Number = 0;
                     private var _terminology:String;
                     private var _description:String;
                     private var _notes:String;
                     private var _insert_date:String;
                     private var _update_date:String;
                     private var _vendor_related:Boolean;
                     
                     public var isDirty:Boolean = false;
      
                     public function get vendor_related():Boolean
                     {
                          return _vendor_related;
                     }
      
                     public function set vendor_related(value:Boolean):void
                     {
                          _vendor_related = value;
                          isDirty = true;
                     }
      
                     public function get update_date():String
                     {
                          return _update_date;
                     }
      
                     public function set update_date(value:String):void
                     {
                          _update_date = value;
                          isDirty = true;
                     }
      
                     public function get insert_date():String
                     {
                          return _insert_date;
                     }
      
                     public function set insert_date(value:String):void
                     {
                          _insert_date = value;
                          isDirty = true;
                     }
      
                     public function get notes():String
                     {
                          return _notes;
                     }
      
                     public function set notes(value:String):void
                     {
                          _notes = value;
                          isDirty = true;
                     }
      
                     public function get description():String
                     {
                          return _description;
                     }
      
                     public function set description(value:String):void
                     {
                          _description = value;
                          isDirty = true;
                     }
      
                     public function get terminology():String
                     {
                          return _terminology;
                     }
      
                     public function set terminology(value:String):void
                     {
                          _terminology = value;
                          isDirty = true;
                     }
      
                     public function get id():Number
                     {
                          return _id;
                     }
      
                     public function set id(value:Number):void
                     {
                          _id = value;
                          isDirty = true;
                     }
               }
      }
      
      

       

      this is a very simple solution but it worked like a charm. Can somebody suggest me something else, a better solution?

       

      thank you

      r. Sandor

       

      P.S.: I didn't include the validators to simplify the example.

        • 1. Re: implementing Dirty Flag for a generated Model (Flex 4)
          carstephun Level 1

          hi,

           

          meanwhile I come a little bit further if you implement the isDirty flag into your remote model and let generate ( to be included in the flex model as well) a model with Flex you can listen to the propertyChange event and do implement a correctly functioning bindable property.

           

          public function VOMessageEntry():void
          {
               addEventListener( PropertyChangeEvent.PROPERTY_CHANGE, handlePropertyChange );
          }
                     
          private function handlePropertyChange( event:PropertyChangeEvent ):void
          {
               if ( event.property != "isDirty" )
               {
                    isDirty = true;
               }
          }
          
          

           

          this code must be inserted into the generated Object itself not in the _Super_objectname source code.

           

          I hope I could helped somebody with this solution.

           

          r. Sandor