Displaying list from databse in gridview
Hi,
I am not sure if this question is related to this: http://knowledge.robotlegs.org/discussions/robotlegs-2/13003-inject-models-into-specific-purpose-view
, 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?
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?
Do I dispatch an event from the service, with the ArrayCollection as the payload?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by roelof on 15 Jun, 2016 06:15 PM
This might provide some kind of answer, but I am not sure how to implement this?
http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/can-i-access-models-and-services-in-my-mediators
Support Staff 2 Posted by Ondina D.F. on 16 Jun, 2016 11:09 AM
Hi Roelof,
There are many ways of accessing services and models, as you've noticed.
I'm a proponent of using events.
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.
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.
Let me know if that helps or if you need more assistance.
Ondina
Example:
Mappings:
View:
Mediator:
Event::
Command:
Service:
3 Posted by roelof on 17 Jun, 2016 04:33 AM
Hi Ondina,
Your example makes perfect sense, and it fits quite well into my current project implementation. I will test it and let you know.
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?
4 Posted by 2morrowman on 17 Jun, 2016 09:51 AM
Hi Ondina,
why in all examples mediators never updates a view on initialization?
My regular mediator looks like this:
Support Staff 5 Posted by Ondina D.F. on 17 Jun, 2016 02:22 PM
Hi Roelof and 2morrowman,
@Roelof
That has nothing to do with robotlegs. :)
In as3 all arguments are passed by reference, including primitive data types (Boolean, String, Number, etc) .
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.
For more details see Adobe's documentation.
Nowadays, 10,000 records shouldn't take much time loading.
But, in my experience, the best way to deal with large data sets is to implement a 'paginator'.
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.
I'm curious, how have you dealt with >10,000 records before using any mvc framework?
@2morrowman
That's really a matter of personal preferences and project requirements.
There are people who would never inject a Model into a Mediator.
Then there are others who would inject Models and Services into Mediators or even into Views.
I think, either approach can 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.
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.
So, your snippet of code looks fine, and if it works for you, go for it. :)
Ondina
6 Posted by roelof on 17 Jun, 2016 03:43 PM
Hi Ondina,
I thought that it is not Robotlegs relevant, but thank you for answering anyway :-)
I understand the concept of pagination, but at this stage my question was more about the underlying memory footprint and as3 behaviour.
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.
Support Staff 7 Posted by Ondina D.F. on 21 Jun, 2016 01:21 PM
Sorry for the delayed response.
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 :)
Ondina
http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/...
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118676...
http://homecoded.com/blog-entry-135.html
http://gskinner.com/talks/resource-management/
http://blog.gskinner.com/archives/2006/06/as3_resource_ma.html
http://www.adobe.com/devnet/flashplayer/articles/garbage_collection...
https://docs.google.com/viewer?a=v&pid=sites&srcid=ZGVmYXVs...
Large data:
http://flexblog.faratasystems.com/index.php/working-with-large-data...
Workers
http://help.adobe.com/en_US/as3/dev/WS0191790375a6482943a72da3138ec...
http://www.bytearray.org/?p=4423
http://jacksondunstan.com/articles/2442
Ondina D.F. closed this discussion on 21 Jun, 2016 01:21 PM.