PDA

View Full Version : Thoughts on dynamic objects


kipsta
11-08-2004, 10:54 AM
I'm writing a test app that monitors a system. The UI consists of a set of 'cards', each representing a live object in the system. The number of 'cards' that can be displayed changes as does the data on existing cards.

Right now, it works in that as the XML that comes back changes (i.e., the cards in the list of cards), the UI changes. What I would like is to add and remove cards as necessary and only update data on existing cards.

For example, below is the basic view I'm using:

<view name="systemCardsView" datapath="cardDataset:/cardList">
<systemCard name="myCard" datapath="card"/>
</view>

So, what I get is N number of cards displayed. In this systemCardsView view, I have a method that requests data from the system and then sets a timer to call itself again (probably a better way of doing this, but the HackMaster is flying wildly). Each time the method is called, all the cards disappear and are then replaced by a new set. This is sub-optimal as, for the most part, the cards remain the same just the data inside of them changes. Occaisionally cards and added and removed from the list.

Is there a way to update the data in the cards themselves?
- Could have the cards themselves make the data request but I want to limit the calls to the server to one large XML file as opposed to N small ones.

To only add 'new' cards?
- Instead of just re-adding everything.

To remove cards that are nolonger there?
- I know I would have to keep track of the cards processed returned and then loop over the cards present and remove the ones that aren't in my list of returned cards (probably some horrendously ineffiecient way to do that using an array).

Any thoughts on any of this would be greatly appreciated,

Thanks...

jivesociety
11-23-2004, 07:58 AM
hey, have you had any luck with your problem? I am faced with the same issue with dynamically removing and adding subviews to views.

kipsta
11-23-2004, 10:14 AM
Yes, I managed to get this all working. I ignored the Laszlo auto-creation of objects and went programatic by instatianting instances of my own objects and creating and deleting as I need.

I can help you if you want more help. Probably better to work it offline. You can email me at kipsta@gmail.com.

metasarah
11-24-2004, 06:55 AM
Even though Kipsta has already pursued a different implementation, I thought I would chime in with another way of solving the original problem.

If you want to have your views controlled by the data, but you don't want the view re-created each time, you should set your datapath to do pooling.

For example:


<view name="systemCardsView">
<datapath xpath="cardDataset:/cardList" pooling="true"/>
<systemCard name="myCard" datapath="card"/>
</view>


When pooling is on, the views are not deleted and re-created when new data arrives. New data is re-assigned to views that already exist. New views are only made if the number of data nodes increases. To use pooling, you want to make sure that the views are completely controlled by their data (set with ondata, applydata or $path bindings) and don't rely on extra state (for example if a card is moved or selected and you want that state to persist, you need to update the dataset or keep it in an separate controller).

Sarah