:::: MENU ::::

Robotlegs Gotcha #3 – You MUST override the clone method in custom events

The problem: You’ve created a custom event which has some custom properties (say an array of data you’d like to pass along), and are dispatching it via the Robotlegs context. You create your new event, populate your data property, and send it on its’ way via the dispatch method:


The event dispatches nicely; however, when it is received (by a command, or listening mediator), the data property is null!


The Solution: The issue here has nothing to do with your event mapping, but rather the event itself. Robotlegs makes use of the clone() method found in all event classes when dispatching its’ events out to the application. You have to make sure that you override the clone() method in your custom events and pass along any custom data properties (in this example, the “data” property) to the new event that gets returned by the clone() method.

So to fix the above example, I would simply override the clone() method in MyCustomEvent and pass in the “data” property as such:


…And that’s all there is to it!

More Robotlegs Gotcha’s:



2 Comments

  • Reply Craig Grummitt |

    Just been pulling my hair out with this gotcha, the problem with gotchas sometimes is you only know what to google to solve the problem after you’ve worked out what the solution is… Now I see the problem’s mentioned in ‘troubleshooting tips’ in the O’Reilly Robotlegs book too…

So, what do you think ?