I think what you should do is create a model in mxml from the value object
and then bind the model to the visual display components and the visual
display components to the model. How the data gets into the value object
from your database, or wherever, is still the same. For example,
 
//  value object
package valueobjects {
  [RemoteClass(alias="contacts.db.PersonBean")]
 
  [Bindable]
  public class PersonVO {
    public var personID:Number = 0;
    public var lName:String = "";
    public var fName:String = "";
    public var DOB:Date = null;
    public var Telephone:String = "";
    public var Address:String = "";
    public var City:String = "";
    public var State:String = "";
    public var Zip:String = "";
    
    public function PersonVO() {
    }
  }
}

Then, in your mxml code, pass in the key, find the data, and display it.
Binding in this way allows you to change the data in either the display
fields or the value object:
 
  <mx:Script>
    <![CDATA[
      import mx.utils.ObjectUtil;
      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import valueobjects.*;
 
      private var _key:Object;
 
      public function get key():Object {
        return this._key;
      }
 
      public function set key(key:Object):void {
        this._key = key;
      }

      private function initComponent():void {
        this.detailObj = new PersonVO();
 
        // get the requested item
        getItem();
      }
      
      /**********************************************
       * Remote Server Calls and handlers
       **********************************************/
 
      // get an instance of the item from the server
      public function getItem():void {
          this.dm.getById(this._key);
      }
 
      private function server_fault(event:FaultEvent):void {
        Alert.show(ObjectUtil.toString(event.fault));
      }
 
      private function get_result(event:ResultEvent):void {
        var detailPerson:PersonVO = event.result as PersonVO;
        this.detailObj = detailPerson;
      }
    ]]>
  </mx:Script>
 
  <mx:RemoteObject
    id="dm"
    showBusyCursor="true"
    destination="ColdFusion"
    source="contacts.db.PersonGateway">
    <mx:method name="getById" result="get_result(event)"
fault="server_fault(event)" />
  </mx:RemoteObject>
 
  <!-- create a model, using the PersonVO.as Value Object class. With this
mxml version of the model, you can bind the form fields back to the object.
--> 
  <model:PersonVO id="detailObj">
    <model:personID>{Number(Person_personID.text)}</model:personID>
    <model:lName>{Person_lName.text as String}</model:lName>
    <model:fName>{Person_fName.text as String}</model:fName>
    <model:DOB>{Person_DOB.selectedDate as Date}</model:DOB>
    <model:Telephone>{Person_Telephone.text as String}</model:Telephone>
    <model:Address>{Person_Address.text as String}</model:Address>
    <model:City>{Person_City.text as String}</model:City>
    <model:State>{Person_State.text as String}</model:State>
    <model:Zip>{Person_Zip.text as String}</model:Zip>
  </model:PersonVO>
 
  <mx:Form width="100%" height="100%">
    <mx:FormItem width="100%" label="Person ID">
      <mx:TextInput id="Person_personID" enabled="false"
text="{this.detailObj.personID}" width="120"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="Last Name">
      <mx:TextInput id="Person_lName" text="{this.detailObj.lName}"
width="200"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="First Name">
      <mx:TextInput id="Person_fName" text="{this.detailObj.fName}"
width="180"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="Date of Birth (MM/DD/YYYY)">
      <!-- make the date field editable so you can just enter the date of
birty instead of having to scroll through the years -->
      <mx:DateField id="Person_DOB" editable="true"
yearNavigationEnabled="true" selectedDate="{this.detailObj.DOB}"
width="100"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="Telephone" required="false">
      <mx:TextInput id="Person_Telephone" text="{this.detailObj.Telephone}"
width="110"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="Address">
      <mx:TextInput id="Person_Address" text="{this.detailObj.Address}"
width="180"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="City">
      <mx:TextInput id="Person_City" text="{this.detailObj.City}"
width="180"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="State">
      <mx:TextInput id="Person_State" text="{this.detailObj.State}"
width="180"/>
    </mx:FormItem>
    <mx:FormItem width="100%" label="Zip" required="false">
      <mx:TextInput id="Person_Zip" text="{this.detailObj.Zip}"
width="180"/>
    </mx:FormItem>
  </mx:Form>
 
You can see a full working demo of this code on my blog at HYPERLINK
"http://www.martinized.us/"http://www.martinized.us/
 
HTH,
Randy



   _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Thursday, January 17, 2008 5:02 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Binding ValueObjects




Ah - good it is Cairngorm.

Initially bind the VO to the component. Well, actually I do bind it's
properties directly to the individual elements of the component initially.

Then what I do is create another Event call something like UpdateVOEvent
and dispatch at the Command level. This then triggers a standard Command
called something like UpdateVoCommand that you can call from all over the
place to trigger the update. Currently I'm actually using it to reset big
forms to their original values. But in answer to your question - the way
I do it is to have a two step process - change the property and then
update the VO.

I think I may have misunderstood the question - how exactly are you
binding a VO to a component without the component knowing which properties
in the VO relate to which elements of the component?

t

> One more question...
>
> How would you bind this update() to the vo in wich we change the
> propertie.
>
> I have VO in the modelLocator, and I change it with command. Then this
> must be updated on the component vo.
>
> How would you bind this?
>
> Thanks,
> Toni
>
>
> --- In HYPERLINK
"mailto:flexcoders%40yahoogroups.com"[EMAIL PROTECTED], [EMAIL PROTECTED]
wrote:
>>
>> Hi,
>>
>> I don't know if this helps, but what I've done in the past is to
> bind the
>> VO and then if I need to update it I had the same problem you were
> talking
>> about. I would change the value, but the VO wouldn't change as the
>> binging goes from the VO to the component, not the other way around. My
>> little work around was to have a function similar to this (assuming
> the VO
>> is called 'voToChange' of type 'VO')
>>
>> private function update():void
>> {
>> var holderVO:VO = voToChange;
>> voToChange = new VO();
>> voToChange = holderVO;
>> }
>>
>> This then changes the VO so the change will go back to the component.
>> Alternatively if you want to set something on the VO you could
> change the
>> function to somethign like
>>
>> private function setSomthing(-something:-Object):void
>> {
>> voToChange.property-ToChange = something;
>> //Call the update function
>> update();
>> }
>>
>> I hope I haven't completely misunderstood what you are having
> problems with.
>>
>> Luck,
>>
>> Tim
>>
>> > I understand that. I know how to bind some class. Problem is, that if
>> > I Bind whole VO to one of my components, if I change something in the
>> > VO (only one var) than nothing will change. I don't want to bind all
>> > the properties separately.
>> >
>> > I can make one example for drawing line:
>> >
>> >
>> > [Bindable]
>> > public class LineVO
>> > {
>> > public var startX:Number;
>> > public var startY:Number;
>> > public var endX:Number;
>> > public var endY:Number;
>> > }
>> >
>> > Than I have one component to draw the line with LineVO.
>> >
>> > var linevo:LineVO=-new LineVO();
>> > linevo.startX=-0;
>> > linevo.startY=-0;
>> > linevo.endX=-20;
>> > linevo.endY=-30;
>> >
>> > var newLine:Line=-new Line();
>> > newLine.vo=linevo;
>> > addChild(newLine)-;
>> >
>> > I only want to bind the whole linevo, not the properties.
>> >
>> > Now if i change some properties like startX or startY, in the line
>> > should be triggered one function that I bind to.
>> >
>> > It is working for me if I bind the every propertie by itself, like
> this:
>> >
>> > BindingUtils.-bindProperty(-newLine,"-onChange"-,linevo,"-startX");
>> >
>> > That is not O.K., because than I have to bind everything manually.
>> >
>> > I hope that now somebody can help me.
>> >
>> > Thanks,
>> > Toni
>> >
>> >
>> >
>> > --- In HYPERLINK
"mailto:flexcoders%40yahoogroups.com"[EMAIL PROTECTED],
"madflexcoder" <[EMAIL PROTECTED]>
>> > wrote:
>> >>
>> >> Put your [Bindable] tag on top of your class and it will make the
>> >> entire class bindable.
>> >>
>> >> [Bindable]
>> >> public class MyVo
>> >> {
>> >>
>> >> }
>> >>
>> >>
>> >> brian..
>> >>
>> >>
>> >>
>> >>
>> >> --- In HYPERLINK
"mailto:flexcoders%40yahoogroups.com"[EMAIL PROTECTED], "toniabc"
<toniabc@> wrote:
>> >> >
>> >> > Hi!
>> >> >
>> >> > I have one problem.
>> >> >
>> >> > I have Value Object that I want to Bind to my custom made
> component. I
>> >> > have no problems to bind every single value from VO to
> component. And
>> >> > if I change something in the VO, that will be changed.
>> >> >
>> >> > But I want to Bind the whole VO (at once, not every value by
> itself).
>> >> > So that I can override the whole VO and changes will be
> automatically
>> >> > trigger the update function in my component. And if I remove
> the VO,
>> >> > than I want to remove my component from view.
>> >> >
>> >> > Thank you,
>> >> > Toni P.
>> >> >
>> >>
>> >
>> >
>> >
>>
>
>
>



 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.516 / Virus Database: 269.19.5/1228 - Release Date: 1/16/2008
9:01 AM
 

Reply via email to