Skip to main content
Participating Frequently
March 5, 2010
Question

Cairngorm development Q

  • March 5, 2010
  • 1 reply
  • 654 views

I have a call to the db which gets a list of order pads.

When this list is returned i then need to create N number of visual order pads

How should this be done. using a data binding and a repeater is not an option. i really just wan to call a function in the view to loop over the result set creating the views

This topic has been closed for replies.

1 reply

Participant
March 8, 2010

Are you talking about Cairngorm 3 or 2?

In Cairngorm 3, which is about Presentation Model Pattern, calling the function directly would be inconsistent to the Architecture.

This doesn't mean that you are not allowed to use any action script in the views, but the code in views should only deal with graphical presentation.

So anyway you should first update the model wih the data returned from the db and the view who is observing model should then update itself.

So if mx:Repeater or custom ItemRenderer is not an option (why actually ? ), there are 2 another solutions:

       1. Dispatch an Event on model update and make the view listen to this event.

       2. Use databinding to a views setter method.

The second approach will result in less coding , but interenally it's implemented by eventdispatching machanism anyway. At least you will probably want to call any function on the model change and not just the setter. Therefore you can implement a generic Observer class.

On the Paul Williams blog entry about the Presentation Model you can find a sample App with 'View Source' option.

http://blogs.adobe.com/paulw/archives/2007/10/presentation_pa_3.html

In this app the author is using the binding to a function approach. It's not exactly your UseCase. The app is displaying alert messages on model changes. To call a function on model change Williams is using an Observer Class, which is placed as Tag in MXML Views. Examine the code in AlbumBrowserView

You can also find an observer class in the Cairngorm 3 library.