[flexcoders] Re: Question about binding and circular reference

2009-03-18 Thread enriirne
Is there anything more sweet than write a long post and see it vanish in the 
air?
Perhaps Chrome plus Flexcoders' Rich-Text Editor (Beta) is asking too much :)

I'll try again, shorter version.

 Another approach, if you're set on binding: Rather than the outer
 component waiting for creationComplete on the inner component to set the
 model value, simply put code in the inner component that waits for
 creationcomplete and creates the component-model return bindings
 programmatically via BindingUtils.

Hi Josh.
I didn't give up on bidirectional binding, but I admit to be close to the metal 
:)
The strategy that seems to work is this:
- a value object with two methods: saveOriginal and restoreOriginal, also 
useful to manage the form's cancel button
- binding through BindingUtils into createComplete
- a mono-binding for date fields, because of a bug in DateField.as

Here is some code. In case of interest, I'll post the implementation.
bindForCreate does a single bind, while bindForUpdate does two.

Enri

// a form
  [Bindable]
  public var vo:SomeVO;
  
  [Bindable]
  private var voOut:SomeVO;
  
  private var cws:Array = []; // used later to unbind
  
  private function creationComplete():void {
if (vo.isNew) {
  extend(cws, bindForCreate(vo, 'date', datefield, 'selectedDate'));
  extend(cws, bindForCreate(vo, 'name', nameField, 'text'));
} else {
  voOut = new SomeVO();
  vo.saveOriginal();
  extend(cws, bindForUpdateException(vo, voOut, 'date', datefield, 
'selectedDate'));
  extend(cws, bindForUpdate(vo, 'name', nameField, 'text'));
  vo.restoreOriginal();
}
  }



Re: [flexcoders] Re: Question about binding and circular reference

2009-03-18 Thread Josh McDonald
Also, try using commiting event only bindings for the trip back to the
model. I don't use it so I'm not sure, but it might be exactly what you're
looking for.

My View Model system doesn't have these problems (and keeps track of dirty
fields, etc), but it's wordy. I do some code-generation with a combination
of BeanScript voodoo in JEdit and a custom Flex app, which cuts down on the
work. I'm not 100% happy with my pattern yet, and need to write a helper
util to better manage binding events, but it's getting close to good enough
to release to the public :)

2009/3/18 enriirne enrii...@yahoo.it

   Is there anything more sweet than write a long post and see it vanish in
 the air?
 Perhaps Chrome plus Flexcoders' Rich-Text Editor (Beta) is asking too
 much :)

 I'll try again, shorter version.


  Another approach, if you're set on binding: Rather than the outer
  component waiting for creationComplete on the inner component to set the
  model value, simply put code in the inner component that waits for
  creationcomplete and creates the component-model return bindings
  programmatically via BindingUtils.

 Hi Josh.
 I didn't give up on bidirectional binding, but I admit to be close to the
 metal :)
 The strategy that seems to work is this:
 - a value object with two methods: saveOriginal and restoreOriginal, also
 useful to manage the form's cancel button
 - binding through BindingUtils into createComplete
 - a mono-binding for date fields, because of a bug in DateField.as

 Here is some code. In case of interest, I'll post the implementation.
 bindForCreate does a single bind, while bindForUpdate does two.

 Enri

 // a form
 [Bindable]
 public var vo:SomeVO;

 [Bindable]
 private var voOut:SomeVO;

 private var cws:Array = []; // used later to unbind

 private function creationComplete():void {
 if (vo.isNew) {
 extend(cws, bindForCreate(vo, 'date', datefield, 'selectedDate'));
 extend(cws, bindForCreate(vo, 'name', nameField, 'text'));
 } else {
 voOut = new SomeVO();
 vo.saveOriginal();
 extend(cws, bindForUpdateException(vo, voOut, 'date', datefield,
 'selectedDate'));
 extend(cws, bindForUpdate(vo, 'name', nameField, 'text'));
 vo.restoreOriginal();
 }
 }

  




-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

Josh 'G-Funk' McDonald
  -  j...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/