Thursday, May 25, 2006

Flex 2, MG4J, and Spring. Bliss...

Perfect timing! I just read this post on Sean's blog, about some of the pitfalls of building Flex front ends for existing Mach II apps and started to write a comment, but it got too long. So I figured I'd just post it. I'm currently working on a big conversion of an application from a very evil and horrible framework to ModelGlue/Spring and Flex 2. This one's Java, but really that's circumstantial at this point, everything is pertinent to CF. I thought it may be an interesting read to write out my development process for this project, so here goes...

I started by flowcharting everything the current app does, and putting names on each bit of data access that is descriptive (this app is bizarrely procedural in its current form!). From there I could identify what my Services would look like, and what methods they would need. That's pretty simplified, but it was almost that easy... Next I defined my DAOs and in certain places I created custom query objects. Too hard to explain, but there's some pretty hard core business logic about HOW to query for data in a lot of cases. Pretty much at the same time I designed the Domain Objects that I would be using at a higher level, raw data in more fine grained views.

OK, next step, test like crazy! That's not really true, because I tend to write test cases for every Domain object as I create them, then every DAO/Gateway as I create them, then all the Services, when I hook them up in Spring, and that goes on and on... The main point here is that I'm concentrating on building and testing my model alone, and constructing services, because I know I'm going to be targeting both Flex and a normal web based app.

So now on to the MG app. Views, controllers, a security system that is pretty standard to what I've been doing for years... This part is pretty easy, in my MG Controllers, I'll put a bunch of stuff in the event, and then I use it in views. Like every one...

Now I have a nice little MG app, and hey it's in Java and really wasn't too hard to write! Amazing, Spring JDBC was a life savor here, btw... But how does this get into Flex! Luckily since I was thinking ahead, even though I would have done everything this way anyway, accessing Spring managed services from Flex is no big deal. I created remote proxies for each of the services, which look up the Spring bean factory through the application context and then retrieve their respective service bean, then defined them in flex-remote-services.xml. That was well, pretty much it! Then I just wrote the Flex front end, and for the most part, the Java to AS object mapping is perfect. As I got deeper into it my proxies started to look a lot more like my MG controllers, as a single method to the service proxies may call multiple methods on a few different services even, returning data keyed in a hashMap. Kind of like adding data the current event in MG. And that's it, my current development process, and what I've been up to for the past few months. Hope it's helpful!

1 Comments:

Anonymous Anonymous said...

Looking forward to see MG4J. Being in love with MG(4CF) it seems like the thing to kickstart java projects for cf developers

4:32 AM  

Post a Comment

<< Home