Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: ItemRenderer with pMVC  (Read 12745 times)
eball
Jr. Member
**
Posts: 15


View Profile Email
« on: March 31, 2009, 12:14:43 »

Can someone point me to a good demo of item renderers being used with pure mvc. (ie: mxml with datagrid using any number of item renderers, all being controlled/referenced with a datagrid mediator)
I find a bunch of samples with just Flex, but none with the second layer of a mediator.

I am trying to make a administration mode of a datagrid (add, edit, delete) and was trying to use a new column of checkboxes to select the record. (say to select all the records you wish to delete)

please help, i have been trying many different things, but none seem to offer a clean way of using itemrenderer and referencing the data set by it.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 31, 2009, 06:53:51 »

Its unlikely that each itemrenderer needs its own mediator. In a grid with thousands of rows this would be terribly inefficient, since you'll probably take the same actions for each one. Try bubbling an event from the itemrenderer/editor and catching it with a mediator for the grid itself. The event will contain a reference to the item renderer/editor. 

-=Cliff>
Logged
eball
Jr. Member
**
Posts: 15


View Profile Email
« Reply #2 on: March 31, 2009, 11:47:06 »

Sorry, I did not write that very clearly. I did not intend a mediator for each record.

I am currently using a bubbled event on a checkbox item renderer. In doing so, i can catch the event and retrieve the associated data with that record.

What i can't seem to do is, get the 'selected' status of the checkbox, b/c i cant seem to get a reference to the checkbox itself.

:
datagrid.mxml
....
<mx: Component id="CheckboxRenderer">
   <mx: VBox>
       <mx: CheckBox id="cb" selected="false" click="dispatchEvent(newEvent("evt", true))" />
   </mx: VBox>
</mx: Component>
 
....
<mx: DataGridColumn .... itemRenderer = "{CheckboxRenderer}"
In the datagrid mediator, i catch the event and can get the data via "evt.target.data"
But how do i get the selected status of the checkbox itself????
I get an error when i try to reference 'cb' (either via datagrid.cb, datagrid.CheckboxRenderer, etc)

 ??? ??? ???
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #3 on: April 01, 2009, 12:55:47 »

I don't know how you get the data from evt.target.data.
Data is a variable in your view?

But wouldn't

evt.target.cb.selected

do it?

Actually it will  always be “true” since you've clicked it and dispatched your event on checkbox click.

EDIT: Sorry, of course it will be "false" if you deselect  it.
« Last Edit: April 01, 2009, 01:57:11 by Ondina » Logged

~ Ondina ~
eball
Jr. Member
**
Posts: 15


View Profile Email
« Reply #4 on: April 01, 2009, 07:40:02 »

Thanks.
"evt.target.cb.selected" worked.

I must have tried everything but that. not sure how i missed it.
Logged
arkadye
Newbie
*
Posts: 4


View Profile Email
« Reply #5 on: April 02, 2009, 01:11:48 »

I have a different question on usage of ItemRenderers with pMVC. In my case, I have a list control that displays messages from different users. The requirement is to show an icon indicating message author's status and author's name at the beginning of each message (IM-like UI). The message VO doesn't contain author's status or name - it contains only author's id and message text. The author's name and status can be retrieved using ContactsProxy's getContactById() method that returns a ContactVO object containing contact's id, first/last name, status, etc. So it seems like the only solution is from ItemRenderer to get a reference to the application facade and from it to ContactsProxy to retrieve the required data. On the other hand, it feels like a violation of pMVC principles, since ItemRenderer is a view component and view components should not access proxies directly.

Could you please explain what is the correct approach?

Thanks,

Arkady.
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #6 on: April 03, 2009, 12:15:14 »

Did I get it right?

You have, let's say, 2 database tables :

messageTable:
messageId
messageText
authorId


authorTable:
authorId
authorFirstName
authorLastName
authorStatus

You make a service call,  request data from the messageTable and when the data arrives your Proxy sends a Notification to the Mediator of the ListView component with the messageVo in the notification's body. The ListMediator updates the ListView's VO and the List gets populated with the messages.

Isn't it possible to have one server call for both, the messageTable and the authorsTable by using the authorId ( of course in case their structure is like I made it up above) and then the proxy should send both VO's to the mediator?
Like this you would have a ListView ( with the List component inside ), a ListMediator, a ListProxy and 2 VO's .
ListView->ListMediator->ListProxy->Database
Database->ListProxy->2VOs->listMediator->ListView

I don't know if that's your scenario or if I understood your question,  but in any case I think you should have a Mediator “mediating” between Proxy and View, not the Facade. I think the puremvc experts would agree on this.

Even if you really need 2 Proxies for getting 2 different VO's you can still  have ONE Mediator communicating with them and the View.

Take a look at Commands, maybe you can use a Command, depending on your use case.

Older members will tell you more about that:)

Ondina
Logged

~ Ondina ~
arkadye
Newbie
*
Posts: 4


View Profile Email
« Reply #7 on: April 03, 2009, 12:50:25 »

Thanks for the try, Ondina.  :)

My scenario is different from what you've described. First of all the messages are retrieved not based on authorId. The collection of messages returned contains messages from different authors. Moreover, they are retrieved from a different server than list of contacts (authors). At any point in time a status of one of the authors may change and then as a result the collection of messages will have to be re-rendered to show the correct status icon for that author. But regardless of how these two collections are retrieved, only the messages collection is assigned as a data provider for the List component. The list component is using ItemRenderer for rendering each message in the list. So ItemRenderer has to access the authors list (proxy) to find the status and name of the author. My question is how to access proxies from the ItemRenderer?

Best regards,

Arkady.
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #8 on: April 03, 2009, 01:03:54 »

Well,then  I'll try  again  :)
You shouldn't access the Proxy from your ItemRenderer or any View component.
I would send an event (bubble=true)  that the mediator would handle, and from there I would try to access the Proxy. 

But I think there are some threads about that problem.
Search for “ItemRenderer”.
« Last Edit: April 03, 2009, 11:29:17 by Ondina » Logged

~ Ondina ~
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: April 04, 2009, 08:05:11 »

Make it easy on yourself. Make a special compound VO that is presented to the list/item renderer, containing all the info you need. Populate the list with the compound VOs rather than trying to make the renderer go get the additional data.

-=Cliff>
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #10 on: April 04, 2009, 08:10:41 »

Hint, assemble the compound VOs in a proxy whose business is to collect the data needed and expose lthe list of compound VOs. You'll probably want it I subscribe to the chat destination so it knows when to update its list of compound VOs and send a note that populates the listbox.

-=Cliff>
Logged
arkadye
Newbie
*
Posts: 4


View Profile Email
« Reply #11 on: April 06, 2009, 12:35:01 »

Thanks Cliff,

That's exactly what I am doing right now. I had to make my MessageVO have a reference the ContactVO. I just wanted to double check whether there is a better solution.

Thanks again.

Arkady.
Logged
Pages: [1]
Print