tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/14800-displaying-list-from-databse-in-gridviewRobotlegs: Discussion 2017-01-15T11:33:39Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-15T18:05:50Z2016-06-15T18:05:50ZDisplaying list from databse in gridview<div><p>Hi,<br>
I am not sure if this question is related to this: <a href="http://knowledge.robotlegs.org/discussions/robotlegs-2/13003-inject-models-into-specific-purpose-view">
http://knowledge.robotlegs.org/discussions/robotlegs-2/13003-inject...</a><br>
, but here is my question anyway. Say for example I have a list of
students store in a sqlite db and I want to display the whole list
in a gridview, what is the recommended way of doing it in RL?<br>
I created a service that returns an ArrayCollection, and on the
view side, I created a Bindable ArrayCollection that is used as a
DataProvider for a DataGrid. How do I link the ArrayCollection in
the service to the ArrayCollection in the View?</p>
<p>Do I dispatch an event from the service, with the
ArrayCollection as the payload?</p></div>roeloftag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-15T18:15:17Z2016-06-15T18:15:17ZDisplaying list from databse in gridview<div><p>This might provide some kind of answer, but I am not sure how to
implement this?</p>
<p><a href="http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/can-i-access-models-and-services-in-my-mediators">
http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/can...</a></p></div>roeloftag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-16T11:09:57Z2016-06-16T11:09:57ZDisplaying list from databse in gridview<div><p>Hi Roelof,</p>
<blockquote>
<p>Do I dispatch an event from the service, with the
ArrayCollection as the payload?</p>
</blockquote>
<p>There are many ways of accessing services and models, as you've
noticed.</p>
<p>I'm a proponent of using events.<br>
If you don't need a Model for your data, then you can let the
mediator(s) listen to an event dispatched by the service with the
result as a payload.</p>
<p>In my example below, the mediator makes a request for data in
its initialize() method, just to illustrate the flow of events.
SomeCommand reacts to the event dispatched by the mediator and
accesses the service. When the service gets the result from the db
it dispatches an event with the result as the payload. The mediator
added a listener for that event so that it can receive the db data
and pass it on to the view. You can run the example to see how it
works.</p>
<p>Let me know if that helps or if you need more assistance.</p>
<p>Ondina</p>
<hr>
<p>Example:</p>
<p><strong>Mappings:</strong></p>
<pre>
<code>mediatorMap.map(SomeView).toMediator(SomeMediator);
injector.map(ISomeService).toSingleton(SomeService);
commandMap.map(SomeEvent.STUDENT_DATA_REQUESTED).toCommand(SomeCommand);</code>
</pre>
<p><strong>View:</strong></p>
<pre>
<code>public function setGridDataProvider(loadedDataProvider:ArrayList):void
{
someGrid.dataProvider = loadedDataProvider;
}</code>
</pre>
<p><strong>Mediator:</strong></p>
<pre>
<code>public class SomeMediator extends Mediator
{
[Inject]
public var view:SomeView;
override public function initialize():void
{
//first add a listener for SomeEvent.STUDENT_DATA_RECEIVED
addContextListener(SomeEvent.STUDENT_DATA_RECEIVED, onStudentDataReceived, SomeEvent);
//then make the request
dispatch(new SomeEvent(SomeEvent.STUDENT_DATA_REQUESTED));
}
private function onStudentDataReceived(event:SomeEvent):void
{
view.setGridDataProvider(event.somePayload);
}
}</code>
</pre>
<p><strong>Event:</strong>:</p>
<pre>
<code>public class SomeEvent extends Event
{
public static const STUDENT_DATA_REQUESTED:String = "studentDataRequested";
public static const STUDENT_DATA_RECEIVED:String = "studentDataReceived";
private var _somePayload:ArrayList;
public function SomeEvent(type:String, somePayload:ArrayList=null, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
_somePayload = somePayload;
}
public function get somePayload():ArrayList
{
return _somePayload;
}
public override function clone():Event
{
return new SomeEvent(type, somePayload, bubbles, cancelable);
}
}</code>
</pre>
<p><strong>Command:</strong></p>
<pre>
<code>public class SomeCommand
{
[Inject]
public var someService:ISomeService;
public function execute():void
{
someService.loadRemoteData();
}
}</code>
</pre>
<p><strong>Service:</strong></p>
<pre>
<code>public class SomeService implements ISomeService
{
[Inject]
public var sharedEventDispatcher:IEventDispatcher
public function SomeService()
{
}
public function loadRemoteData():void
{
//select from db
//here mocking the db data and the result's handler
var fakeResult:ArrayList = new ArrayList([
{Student:'Ondina', Question:'Why is the sky blue?'},
{Student:'Roelof', Question:'Why is the grass green?'}]);
onRemoteDataLoaded(fakeResult);
}
private function onRemoteDataLoaded(result:ArrayList):void
{
// read the result and send it as the payload of SomeEvent
// here sending the fake result as array list:
sharedEventDispatcher.dispatchEvent(
new SomeEvent(SomeEvent.STUDENT_DATA_RECEIVED, result));
}
}</code>
</pre>
<pre>
<code>public interface ISomeService
{
function loadRemoteData():void
}</code>
</pre></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-17T04:33:26Z2016-06-17T04:33:26ZDisplaying list from databse in gridview<div><p>Hi Ondina,</p>
<p>Your example makes perfect sense, and it fits quite well into my
current project implementation. I will test it and let you
know.</p>
<p>One last question on this topic, and this might actually be on
AS3 level: When you pass the Arraylist as a payload, does RobotLegs
/ AS3 actually only pass a pointer to the current Arraylist in
memory? If my query returns a result of, say 10,000 records with a
lot of information per row, will above method still be
recommended?</p></div>roeloftag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-17T09:51:10Z2016-06-17T09:51:32ZDisplaying list from databse in gridview<div><p>Hi Ondina,</p>
<p>why in all examples mediators never updates a view on
initialization?</p>
<p>My regular mediator looks like this:<br></p>
<pre>
<code>public class SomeViewMediator extends Mediator {
[Inject]
public var view:SomeView;
[Inject]
public var someModel:SomeModel;
override public function initialize():void {
updateView();
addContextListener(SomeEvent.DATA_UPDATE, updateView);
}
protected function updateView( event:Event = null ):void {
view.data = someModel.data;
}
}</code>
</pre></div>2morrowmantag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-17T14:22:49Z2016-06-17T14:22:49ZDisplaying list from databse in gridview<div><p>Hi Roelof and 2morrowman,</p>
<p>@Roelof</p>
<blockquote>
<p>One last question on this topic, and this might actually be on
AS3 level: When you pass the Arraylist as a payload, does RobotLegs
/ AS3 actually only pass a pointer to the current Arraylist in
memory?</p>
</blockquote>
<p>That has nothing to do with robotlegs. :)<br>
In as3 <strong>all</strong> arguments are passed by reference,
including primitive data types (Boolean, String, Number, etc) .<br>
The only difference between primitive and complex data types is
that primitives behave like they were passed by value, because as3
stores them internally as immutable objects.<br>
For more details see Adobe's documentation.</p>
<blockquote>
<p>If my query returns a result of, say 10,000 records with a lot
of information per row, will above method still be recommended?</p>
</blockquote>
<p>Nowadays, 10,000 records shouldn't take much time loading.<br>
But, in my experience, the best way to deal with large data sets is
to implement a 'paginator'.<br>
I always display a limited number of results in a datagrid. I use
buttons to navigate the data set, and to load subsets of data.
Search the internet for pagination, paginated datagrid, data
paging.. if you're interested in this approach.</p>
<p>I'm curious, how have you dealt with >10,000 records before
using any mvc framework?</p>
<p>@2morrowman</p>
<p>That's really a matter of personal preferences and project
requirements.</p>
<p>There are people who would never inject a Model into a
Mediator.<br>
Then there are others who would inject Models and Services into
Mediators or even into Views.<br>
I think, either approach <em>can</em> be valid, but it depends on
the overall structure and requirements of a certain project and the
experience of the developers how it is implemented.</p>
<p>I tend to use events for the communication between classes, but
I also have use cases in my projects where injecting a model into a
mediator makes sense and it also doesn't create too much
coupling.</p>
<p>So, your snippet of code looks fine, and if it works for you, go
for it. :)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-17T15:43:11Z2016-06-17T15:43:11ZDisplaying list from databse in gridview<div><p>Hi Ondina,<br>
I thought that it is not Robotlegs relevant, but thank you for
answering anyway :-)</p>
<p>I understand the concept of pagination, but at this stage my
question was more about the underlying memory footprint and as3
behaviour.</p>
<p>I have not previously worked with >10,000 records directly,
was more involved on the QA side of such projects. I am busy with
feasibility study on a possible project that will have that amount
of records, but it is too early to be exact.</p></div>roeloftag:robotlegs.tenderapp.com,2009-10-18:Comment/401226962016-06-21T13:21:33Z2016-06-21T13:21:33ZDisplaying list from databse in gridview<div><p>Sorry for the delayed response.</p>
<p>I put together a few links to articles about arrays, memory
management, workers.. that might be of interest to you. I'm going
to mark this thread as resolved for now. You are free to re-open it
if you think that there are some robotlegs-related aspects of your
question that have not been answered yet. And, of course you can
create new threads for other issues you may encounter as your
project progresses :)</p>
<p>Ondina</p>
<hr>
<ul>
<li>Array vs Vector vs ByteArray:</li>
</ul>
<p><a href="http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/vectors-and-bytearrays.html#articlecontentAdobe_numberedheader_3">
http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/...</a></p>
<p><a href="http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118676a5388-8000.html">
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118676...</a></p>
<p><a href="http://homecoded.com/blog-entry-135.html">http://homecoded.com/blog-entry-135.html</a></p>
<ul>
<li>Memory management + garbage collection</li>
</ul>
<p><a href="http://gskinner.com/talks/resource-management/">http://gskinner.com/talks/resource-management/</a><br>
<a href="http://blog.gskinner.com/archives/2006/06/as3_resource_ma.html">http://blog.gskinner.com/archives/2006/06/as3_resource_ma.html</a><br>
<a href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html">
http://www.adobe.com/devnet/flashplayer/articles/garbage_collection...</a><br>
<a href="https://docs.google.com/viewer?a=v&pid=sites&srcid=ZGVmYXVsdGRvbWFpbnxmbGV4amF2YWdvdXJhdnxneDo1YWE4ZTVkYTJjM2RhYTVj">
https://docs.google.com/viewer?a=v&amp;pid=sites&amp;srcid=ZGVmYXVs...</a></p>
<ul>
<li>
<p>Large data:</p>
<p><a href="http://flexblog.faratasystems.com/index.php/working-with-large-data-sets-in-flash-player/">
http://flexblog.faratasystems.com/index.php/working-with-large-data...</a></p>
</li>
<li>
<p>Workers</p>
</li>
</ul>
<p><a href="http://help.adobe.com/en_US/as3/dev/WS0191790375a6482943a72da3138ec8eec7e-8000.html">
http://help.adobe.com/en_US/as3/dev/WS0191790375a6482943a72da3138ec...</a></p>
<p><a href="http://www.bytearray.org/?p=4423">http://www.bytearray.org/?p=4423</a></p>
<p><a href="http://jacksondunstan.com/articles/2442">http://jacksondunstan.com/articles/2442</a></p></div>Ondina D.F.