At first glance, the Repeater control looks extremely powerful, but now I'm having second thoughts.
Problem at hand:
Adding Event Listeners to the children
Repeater object is bound to and iterates through an ArrayCollection creating new Vbox children for each item. Now for each child, the Repeater object will fire off a "repeat" event, where I'm tempted to add the eventlistener (for mouse events). No problems so far, but, what happens when the ArrayCollection changes, how should I remove the EventListeners for all the old children? Is there an array of children containing my Vbox instances that I'm skipping over in the docs? Are eventlisteners cleaned up nicely when the object they are attached to is destroyed?
-C coder lost in flex/actionscript
I would avoid using Repeaters entirely. From a performance standpoint they are very slow because the items are frequently destroyed and recreated. You are better off using a List-based control and implementing an itemRenderer.
Event listeners by default are strong references, so if you do not remove your event listeners it will prevent the object from being garbage collected. You can use the optional 5th parameter in the addEventListener called "weakReference" and set the value to true to add an event listener that will not prevent GC.
To better deal with events in your itemRender component, you can implement the IDropInListItemRenderer interface. This will give you access to "listData" which has an "owner" property which is the actual List object itself. In your itemRenderer, dispatch a custom Event containing the necessary data through the owner. If you add an event listener to the List control after it's created then you can do the event handling in the component containing the control.
Ok, seems I needed to give the vbox an id, after that I was able to access that id as an array of vboxes. After adding the event handler, I was able to use the event's currentTarget.getRepeaterItem() as a reference to the object in the ArrayCollection.
Cleaning up the event handlers was taken care of by looping over the vbox array and removing the handlers.
Not too worried about performance, as there are few items and they rarely change over the time the program is running, though those items would be different almost every run. Unless it's needlessly destroying and recreating items, it shouldn't be much of an issue.
Related
I am looking for a way to detect when a new a-frames element has been added as a child of a given element(like "child-attached") but doesn't fire until the elements components have been initialized
alternatively, is there an event that is raised after an elements components have all been initialized?
The loaded event will fire when all components initialized. This event doesn't bubble. I would have a component that you attach to the dynamically added entities, and listen to load event. Better yet, set dependencies to wait for the exact component you need.
Related, the componentinitialized event will fire for each initialized component.
I have an ObservableCollection I'm attempting to bind to a ListView. I create everything just fine. The collection has multiple items in it (checked from both ends of the binding in ModelState and VisualState, but the View is never updated. I went ahead and bound directly to the ModelState's piece and everything worked just fine.
I suspect the cause is that INotifyCollectionChanged is not being sent through the binding. Is this something I can fix or is this a bug?
The binding between VisualState and ModelState are only done at the top level property. Hence if you replaced the ObservableCollection with a new ObservableCollection, that would be propagated. But the Binding doesn't know anything about the properties, hence it's not going to know about the INotifyCollectionChanged.
But, the binding should just copy the reference value from ModelState to VisualState, hence they should both reference the same object, therefore, adding a value at either end, should show a value change at the other end, and a raise of the event.
I would try manually attaching to the event, to confirm it is being raised.
I have a problem that I have no idea to resolve it. In my application, I have a ViewStack with 2 children.
In the first view of the ViewStack, I have a datagrid with a XMLListCollection as dataprovider. In this view, user chooses a record from the datagrid then he passes to the second view.
In the second view, all the data chosen from the record will be loaded into different textInputs for modification.
My problem is, how can I pass these data from one view to another in ViewStack. I have done a search for the answer in this forum but no thread responses to my question.
All replies will be highly appreciated.
Thanks and best regards,
LE Hai-Binh
You can use Event handling mechanism. When you select a record in datagrid (in first child of Viewstack), create an Event object and put all the data into it and dispatch it. On the second child of Viewstack write a listener of this event. In the listener method extract the data from Event and do whatever you want to do with the it.
This is a little difficult to explain so please bear with me.
I have a procedure that is generating some radio buttons and assigning a CheckedChanged postback event based on the level being passed through (up to 4 levels). When the first level is checked (radio button selected) the postback event rb_CheckChanged00() is called and a check is done to see if this item has any children, if it does, it will create more radio buttons and assign rb_CheckChanged01 to the CheckChanged event for these - This part is working fine.
The issue I have is when I select the second Radio Button that has been created (the child), it doesn't seem to go to the post back event at all. The page is posting back when I click on it but everything resets because it won't go into rb_CheckChanged01.
I know this info is quite vague but I am hoping someone has an idea on how the post back event works and if I am somehow using it incorrectly.
Using: ASP.NET 2.0, IIS7
Thanks.
Most of the time when the dynamically created control's events are not fired, it's because the controls are 'reset' upon postback.
To make sure the same controls get created each and every time make sure that the control's IDs are set to the same values each and every time, before the ViewState is loaded. This way, when the control is added to the control collection of the page, once the ViewState is loaded, it'll persist it's properties. (just to describe what happens, in a nutshell)
One of the best articles I've read on this topic is this one. Make sure you read it, to fully understand what's happening in the background.
Looks like the child RBs are cleaned before they are able to trigger the event. From my personal experience, it's best to keep track of those dynamically generated objects, and regenerate them in every postback. The events will start to trigger :)
Your controls and events are not registered in the ViewState because dynamic controls need to be loaded in the Page_Init. Because they're not persisted in the ViewState, they won't be registered with events. A similar question:
Problem with dynamic controls in .NET
Only 1 thing can cause this, you create the rb's on page_load and don't add them to a List<> or something similar and that object to Session. What you need to do is when you create the items, Add them to a List and add that list to Session["RadioButtons"] and if the Page.IsPostBack is true, load your controls one by one from your list which is kept in your session to your page.
I have a custom component on which I have bound an array collection to one of its proeprties:
<comp:MyComp id="comp" prop="{images}" />
images is an arraycollection
In the components' code I would like to know which event to listen on everytime images updates props.I tried a setter on props but the setter only gets called once when props is first set. I tried the collection event but I get "Update" events sent on top of 'add' and 'remove' events and I would rather not have to manage those. So is there an event(flex or otherwise) that is fired every time a component property is updated by a bindable property?
I think you want to listen to the collectionChange event on the prop property. This should fire every time an element in your ArrayCollection changes.
Be warned that changing the source of images not fire the collectionChange event, nor will it fire the prop setter.