Select to view content in your preferred language

One arraycollection for 2 widgets

1119
5
Jump to solution
05-01-2013 12:51 PM
AaronPerry
Occasional Contributor
I have 2 widgets that need to share an arraycollection.  I want to create the collection once in which ever widget initializes first, and then store it for them both to use from that point forward.  I've looked at DataManager and I can see how I would share data in an event driven way. What I don't see is a way to store data in DataManager when either widget initializes and 1) check for the data's existence when the second widget loads so I don't have to create it again, and 2) how I would retrieve the stored data in the second widget if I could check for its existence in DataManager. 

For reference, the driving force here is that I have comboboxes in each widget that need to use the same data.

Can anyone explain how I would share a single collection of data between widgets that only gets initialized once? 

Any help would be greatly appreciated.

Thanks,
Aaron
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KennyHoran
Regular Contributor
I've been there.  It's a bit hard to visualize but it's possible to share data.  Let's see if I can explain it.

When the data is initialized you should dispatch a DATA_PUBLISH event containing the data.  Each of your widgets should listen for that event, then save a copy of the data.

But what if the DATA_PUBLISH happens before your widget is initialized?  For that you'll need the DATA_SENT event.  Dispatch a DATA_FETCH to trigger it, then it will return the DATA_PUBLISH results if they exist.

So, by using DATA_PUBLISH and DATA_SENT you can share data between widgets regardless of where or when it originates.

View solution in original post

0 Kudos
5 Replies
KennyHoran
Regular Contributor
I've been there.  It's a bit hard to visualize but it's possible to share data.  Let's see if I can explain it.

When the data is initialized you should dispatch a DATA_PUBLISH event containing the data.  Each of your widgets should listen for that event, then save a copy of the data.

But what if the DATA_PUBLISH happens before your widget is initialized?  For that you'll need the DATA_SENT event.  Dispatch a DATA_FETCH to trigger it, then it will return the DATA_PUBLISH results if they exist.

So, by using DATA_PUBLISH and DATA_SENT you can share data between widgets regardless of where or when it originates.
0 Kudos
DougBrowning
MVP Esteemed Contributor
When I had to do this I just "cheated" and used a global var.  It was just so much easier.
0 Kudos
AaronPerry
Occasional Contributor
Thanks so much Kenny.  This is what I needed to hear.  I had seen a lot of posts about sharing data with DataManager, but this made it click after careful consideration of your explanation. I may post some basic code here later to help others who need help trying to "visualize" it.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
All,

   Here is a thread and a PDF explaining widget communication:

http://forums.arcgis.com/threads/38899-Widget-Communication-Explained
0 Kudos
AaronPerry
Occasional Contributor
Thanks so much Robert!  That is a great document.  I am lost as to why my plethora of searches on the subject here did not yield that thread. 

Thanks again all.
0 Kudos