views:

20

answers:

1

I'm starting to learn a little Flex just for fun and maybe to prove that I still can learn something new :) I have some idea for a project and one of its parts is a tree component which could display data in different ways depending on configuration.

The idea

There is list of objects having properties like id, date, time, name, description. And sometimes list should be displayed like this:

  1. first level: date
  2. second level: time
  3. third level: name

and sometimes like this:

  1. first level: year
  2. second level: month
  3. third level: day
  4. fourth level: time and name

By level I mean level of nesting of course. So, we can have years, that have months, that have days, that have hours and so forth.

The problem

What could be the best way to do it? I mean, should I prepare data for different ways of nesting outside of component or even outside of flex? I can do it at web service level in C# where I plan to have database access layer and send to flex nice and ready to display XML or array of objects. But I wonder if that won't cause additional and maybe unneccessary network traffic.

I tried to hack some code in my component to convert my data objects into XML or ArrayCollection but I don't know enough of Flex and got stuck on elimination of duplicates or getting specific data by some key value. Usually to do such things I have STL with maps, sets and vectors and I find Flex arrays and even Dictionary a little bit confusing (I've read language reference and googled without any significant luck).

The question

So, to sum things up: should I give my tree component data prepared just for chosen type of display or should I try to do it internally inside component (or some helper class written in ActionScript)?

ADDITIONAL QUESTION

Would it be a good approach to prepare separate data models for each way of display and some converter to transfer data between them and resulting model would be binded to component as a dataProvider? Or maybe there is some other clever way to do it and my data will reorganize automagically by themselves? :)

A: 

I would favor receiving a raw stream of data from your web service and process it in various ways within the flex client (in a helper Actionscript class). Here are the advantages I see:

1) This gives a nice separation of responsibilities. E.g. the web service should know about the data but not what ways it will be displayed.

2) Faster processing and client responsiveness. Swapping views will not involve calling your web service and the Flex client will likely be faster processing the data itself than the extra web traffic

3) Increased availability. Without extra calls to your web service, there is less of a chance of a network failure.

Chris Knight
my thoughts exactly! so I added some additional question to help you help me go in right direction with this thing :)
grapkulec
You can either pre-process both into two different data providers which then get dynamically swapped to your component by some action, or the action itself reconstructs the single data provider to match the new required format. The first requires more upfront processing but faster switching between the two, while the second is the reverse (faster initial load, slower switching). Of course, if the size of your data isn't significant, then the final implementation won't really matter and it becomes a matter of personal preference.
Chris Knight