Using TransferObjects as Mach-II Event-Beans

November 4th, 2009

I wrote an article for the fantastic people at the Mach-II project called Using TransferObjects as Event-Beans. I was pretty jazzed at the opportunity to contribute back to the project that’s made software development so much fun for me lately.

A few days later, I’m starting to notice that the approach I was taking is an infeasible one, or at least a suboptimal one. The main goal I had in mind was code-reuse; since the TransferObjects are generated dynamically and Mach-II has the amazing event-bean command that populates a bean with form values automatically, that means I don’t have to write any code!

But of course, there’s a gotcha.

Mach-II doesn’t insist that the object being used as an event-bean only accept Strings as arguments, but it heavily hints at it. There are no hooks into the binding process (that I know of, please correct me if I’m wrong), so errors propagate up to the surface and the user gets a framework error instead of a nice “here’s what you did wrong” message. For example, if one of the fields is a Date, everything binds correctly if the user enters a convertible string, like “11/4/2009″. However, if the entry is blank (and this is true of numerical types too) a framework error is thrown.

And don’t even get me started on binding Select elements or Checkbox/Radio groups using TransferObjects.

Now, this isn’t the fault of the framework. In my zeal I’m trying to get it to do something that it wasn’t meant to do. But it raises some interesting questions on the ‘right way’ to handle form requests. It’s such a rudimentary operation that one would think it had been solved so satisfactorily that even children would know how to do it. I’m a pretty smart guy, why can’t I find a method I’m happy with?

Also, with Validation looming on the horizon (with the Mach-II 1.9 release), is my bonkers approach mainstream enough that I should be championing it to the development team? With decently open parameter binding sitting behind the event-bean command I could get my approach working very, very well, and the code would be absolutely pristine. But is it worth it? Do enough other people develop the ‘Mike way’?

The answer I think is more research. Look for open-source applications that are using Mach-II and see how they handle form submission. Perhaps start with the Dashboard (which is a wonderful piece of tech that makes my life a whole lot easier). There must be some OS projects out there using Mach-II for form submissions in a way that makes sense to me.

Or perhaps, should I abandon my desire to use TransferObjects as event-beans?