1

I am using a command pattern, so any changes to object state need to happen within a command execution. A normal itemeditor in a DataGrid would just make its changes on the underlying bound object, but I need to intercept that change and make it use a command.

I'm pretty new to flex, so I'm looking for ideas of how to implement this. A basic example is that I have an object with a "date" field. In the datagrid I am using a flex "DateField" component as the itemeditor. When I select a new date, I don't want it to update the datasource, I want it to call a different method where I can access the newly selected value and pass it to a command to execute. Any tips would be greatly appreciated. Thanks in advance.

Ocelot20
  • 10,510
  • 11
  • 55
  • 96

2 Answers2

2

Use the itemEditBegin and/or itemEditEnd events on the DataGrid and build your command in the handler. This page has a few examples of capturing the edit operation with those events.

drkstr
  • 609
  • 6
  • 9
1

In my opinion, you're over-engineering this to hell, to the point that it becomes unusable. Why would you need a command to just change data on the fly? I've been doing Flex for 3 years and I yet to see it done this way. The only time commands are used is for receiving information from the server.

Either way, if you really want to implement it (against my recommendation), you would probably want to do event bubbling with a controller listening higher up the display list for the event, then from there trigger a command. From within the item renderer:

this.dispatchEvent(new Event('someEvent', true));

And then higher up the display list:

dataGrid.addEventListener('someEvent', someEventHandler);

And within the handler you can run the command.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • @J_A_X I agree it seems a bit overkill in a simplified description of the issue, but usually when someone is talking about patterns they are working on a large application and may be required to follow the design conventions used in the rest of the app. – drkstr Mar 31 '11 at 02:02
  • My expertise is large Flex app development. This pattern is not used in conventional Flex apps because it doesn't make sense. If he has a good explanation for it, then sure, but I've never seen it done like this. So I'm thinking he probably comes from a java or .net background where he doesn't know exactly how it should be done on the front-end. – J_A_X Mar 31 '11 at 02:12
  • As is mine. We use the Command Pattern all the time for modular "dashboard" style apps. It is also very prevalent in most Dependency Injection (DI) frameworks. But I mostly agree with what you. All I was saying is that without knowing more about the scenario, we are hardly in a position to make architectural recommendations. There is a time and a place for everything, even the Command Pattern. :) – drkstr Mar 31 '11 at 02:24
  • yeah, but in DI framework, you probably use the Command pattern to request/send information from the server and not use it to just update a model. – J_A_X Mar 31 '11 at 02:31
  • touché :D ...probably best not to pollute the display with business logic. Although, the command pattern is king in data driven applications (aka runtime markup language). But I agree it's best to leave those matters to the business logic layers. – drkstr Mar 31 '11 at 06:38
  • I'm using the command pattern for undo/redo functionality. It just so happens that this datagrid has a couple of fields that have major downstream impacts when they are changed. Believe me, I'm up for any suggestions on a better way to do this, but so far the command pattern has been serving this application very well for the features I'm looking for. – Ocelot20 Mar 31 '11 at 11:36