tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/418-creating-a-temporary-data-store-in-a-mediatorRobotlegs: Discussion 2018-10-18T16:35:34Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-03T12:33:47Z2011-11-03T12:33:47ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>I'm creating a panel in a AIR app in which users add information
then when the user saves the form all the details in the form are
added to the model and the 'header' text of the form is displayed
in another panel. Then the user can reuse the form to add a new set
of data.<br>
Also the user can select a entry from the other panel and this
fills the first panel with all the saved details, so they can
update the information.</p>
<p>To store this info I'm using a Value Object, which I add to the
main models array collection when I save the details in the panel,
then to update the details I find the Value Object within the
ArrayCollection and pass that to the mediator to populate the
view.</p>
<p>The problem I'm having is that I sometimes get a mix of data. Is
there a cleaner method of creating this type of application?</p>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-03T13:57:11Z2011-11-03T13:57:11ZCreating a temporary data store in a mediator<div><p>I am not quite sure what you mean by "mix of data".<br>
I think a better way would be to use a service that updates your
model after the user saves the data instead of letting the mediator
modify the model (also this way you make sure model and your saved
data are always the same).<br>
I also think that it is the job of the view to know which vo it is
showing (correct me, if I am wrong, I am not so sure about
this).</p></div>andreastag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-03T14:20:22Z2011-11-03T14:20:22ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>When I said 'mix of data' what happens is that I have an array
within this Value Object which sound time shows the previous list
of items in the array.</p>
<p>What is not happening is that the Value object that manages the
data of the view is not getting cleared out complete, which I know
I could do this using:</p>
<p>myArray = [];</p>
<p>This causes the array to be null if I try to add new items to
it.</p>
<p>What I want to do is:</p>
<ol>
<li>Save the details entered in a form to a Value Object</li>
<li>Add that Value Object to the model</li>
<li>Create a new Value Object and add that to the model<br>
3a. Load a existing Value Object from the model<br>
3b. Amend the details in the loaded Value Object<br>
3c. Update the match Value Object in the model</li>
</ol>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T10:59:06Z2011-11-04T10:59:06ZCreating a temporary data store in a mediator<div><p>Hi Stephen,</p>
<p>I, too, would like to help you find a solution, but I have a
train to catch in a few hours.<br>
I’m sure someone else will chime in with an answer or
suggestion.<br>
You could also search the forum for “vo in view”.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T11:08:32Z2011-11-04T11:08:32ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>I will, thanks for advice, good luck catching your train.</p>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T11:17:52Z2011-11-04T11:17:52ZCreating a temporary data store in a mediator<div><p>Hi Steven,</p>
<p>Could you start again and explain it a little more slowly? I'm a
bit confused - and I think part of that confusion is just a few
typos (there's a "sound time" which I can't work out), and partly
I'm not sure why:</p>
<pre>
<code>myArray = [];</code>
</pre>
<p>Would cause the array to be null - because that's the syntax for
creating a new, empty array.</p>
<p>The thing that most immediately springs to mind is that I
usually find that when I'm working with VOs and models I have to
make a copy of any array I make changes to using
<code>slice()</code> because Arrays are passed by reference, not
value. So any updates you make to an array passed by value will
immediately update the data in the original item as well, which
usually isn't what I want to happen.</p>
<p>But that may be unrelated.</p>
<p>So - tell us what currently happens, exactly what you're seeing
and what you're expecting to see, and I'm sure we can figure it out
with you.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T12:07:35Z2011-11-04T12:07:35ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>Ok, here's a explanation of what I'm trying to do, hope it
helps.</p>
<p>I'm creating a extension for Creative Suite, it has two panels,
one above the other. The top panel is a data entry form, the second
panel shows a list of the saved details from the top panel.</p>
<p>The way I have this working is, a value object (VO), which
contains a string and a array. Is being used to store/package the
details of the form being created.</p>
<p>A user completes the form by entering a title it a textbox, this
is stored in the string value in the VO. They then select items
from the document they are working on in the Creative Suite
application.</p>
<p>Every time the user selects a item they click a 'add' button,
this gets the name of the selected item and adds it to the array of
the VO. It also causes the view to display the name in a textbox,
every time they click on the add button a new textbox is added to
the panel.</p>
<p>Once they have added all the selected items, they click the
'save' button. This fires a event that sends the VO to the
application model.</p>
<p>The application model contains a Array Collection, which VO are
added or removed.</p>
<p>When a VO is added to the model, the name (the string value in
the VO) is displayed in the second panel. Every time a new VO is
added to the model the name is displayed in a list in the bottom
panel.</p>
<p>When the save button is click the top panel is cleared, this
means the name textbox is cleared and the added textboxes that show
the names of all the selected items, are removed.</p>
<p>The user then has 2 choices either enter a new name and select
new items from the CS document or select a name from the bottom
panel list to edit a save VO.</p>
<p>The problem I'm having is if the user decides to enter the
details of a new item in the top panel, when they select a new item
from the CS document the previous set of items are also shown, with
the new item. It appears that the array is not being cleared.</p>
<p>So I added the function that is called when the save button is
clicked, which clears the form (it empties the name textbox and
removes all the added item textboxes).</p>
<p>In this 'clearForm()' function I set the array to:</p>
<p>myValueObject.myArray = []</p>
<p>This works, but when I later then select a saved item name from
the bottom panel (this should populate the top panel with all the
details of the saved VO from the models ArrayCollection) only the
name is returned but the items array is not. So the user does not
see the list of items they have selected from the CS document they
are working with.</p>
<p>If I don't clear the array like this, then when the user tries
to add new items to a new entry in the top panel, all the existing
items from the previously saved VO are shown.</p>
<p>Really all I want to do is:</p>
<ol>
<li>enter details in a form</li>
<li>save these details<br>
3a. enter a new set of details and save them<br>
3b. select a already saved set of details, view them and update
them</li>
</ol>
<p>Sounds simple, but somewhere I have gone wrong.</p>
<p>Does this helps?</p>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T12:11:22Z2011-11-04T12:11:22ZCreating a temporary data store in a mediator<div><p>Hi Stephen,</p>
<p>when you do</p>
<pre>
<code>myValueObject.myArray = []</code>
</pre>
<p>Is the myValueObject a new one, or might it still be referencing
the same object that you were using before?</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T12:18:57Z2011-11-04T12:18:57ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>In my view I have a temp array that stores all the selected
items name, this is then set to the array in the value object like
this:</p>
<p>myValueObject.myArray = myTempArray;</p>
<p>then on the save function which is called by the save button I
have a function which clears the form and sets this temp array like
this</p>
<p>public function clearForm():void</p>
<pre>
<code> {
this.nameTxt.text = "";
this.myTempArray = [];
this.childrenTextboxContainer.removeAllChildren();
this.saveBtn.enabled = false;
this.updateBtn.enabled = false;
}</code>
</pre>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T12:26:43Z2011-11-04T12:26:43ZCreating a temporary data store in a mediator<div><p>Hi Stephen, I'm afraid I've got no idea what's causing your
problem then.</p>
<p>Is the view coming and going from the stage? Or is it always
visible?</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T12:30:28Z2011-11-04T12:30:28ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>Its always visible, its a AIR app that runs inside a Creative
Suite</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T13:54:57Z2011-11-04T13:54:57ZCreating a temporary data store in a mediator<div><p>Stephen, just a quick observation or rather a few questions
before heading to the train station:</p>
<p>Is the VO in your view the same as the one you’re
manipulating in your model? You are talking about adding and
removing VOS in the model, but how are you refreshing the list with
the new VOS? So there isn’t just <strong>one</strong> vo, but
several vos?<br>
You are emptying the VO’s array in the view, but it seems
that the method in your view, which is responsible for what you
described here:<br>
“if the user decides to enter the details of a new item in
the top panel, when they select a new item from the CS
document” is picking the old VO. So I’d try to see if
there is a need for doing something like this: myVO:SomeVO=new
SomeVO(), or if you want SomeVO to be always the same and just
empty its vars.<br>
Maybe you should tell Stray more about the structure of your models
and vos and paste in here the methods from your view where you are
using these vos.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-04T14:49:31Z2011-11-04T14:49:31ZCreating a temporary data store in a mediator<div><p>Try this:<br>
1. myValueObject.myArray = myTempArray;<br>
2. clearForm: this.myTempArray = [];<br>
and then :<br>
3. myValueObject.myArray = [];</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-11T12:09:46Z2011-11-11T12:09:46ZCreating a temporary data store in a mediator<div><p>Hi,</p>
<p>I was wondering if the problem is where my ArrayCollection is
being instantiated everytime I call my save function.</p>
<p>I have mapped my model as a singleton, like this:</p>
<p>injector.mapSingletonOf( IDynamicGroupsModel, DynamicGroupsModel
);</p>
<p>Inside that I create a ArrayCollection like this:</p>
<p>private var dynamicGroupCollection:ArrayCollection = new
ArrayCollection();</p>
<p>then my save function looks like this:</p>
<p>public function saveGroup(dynamicGroup:DynamicGroupVO):void</p>
<pre>
<code> {
dynamicGroupCollection.addItem( dynamicGroup );
groupSaved();
}</code>
</pre>
<p>Is there a way I can map the ArrayCollection as a singleton, so
that only the one instance of the array collection is used.</p>
<p>Stephen</p></div>stephenadams1tag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-11T12:16:11Z2011-11-11T12:16:11ZCreating a temporary data store in a mediator<div><p>Hi Stephen,</p>
<p>I wouldn't map the collection itself, but if you create a simple
wrapper class that just holds the array collection, you can map
this as a Singleton.</p>
<p>But if you've only got one instance of it inside the
DynamicGroupsModel then this is guaranteed to be single.</p>
<p>So - can't you just make sure the collection is only
instantiated once inside the model? Just make it a member of that
model and its 'singleness' will be ensured.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/110738782011-11-11T12:20:29Z2011-11-11T12:20:29ZCreating a temporary data store in a mediator<div><p>Cool, thanks.</p>
<p>That means I can rule that problem out.</p>
<p>Stephen</p></div>stephenadams1