|Struts and Spring
||[Dec. 4th, 2005|05:58 pm]
With this project, we used struts for the web facing side (controller of MVC, forms, validation etc). We then used spring for dependency injection in Model + DAO, providing the setup for lookups, helping simplify the JDBC stuff in the DAO, and with the security.|
Our experiences with Spring were really positive. Almost all the time, whenever we wanted to extend something, there were extension points built in. The few times there weren't, either there were plans to support extension there in the next version, or we'd report it and be told they'd support it for the version after next + suggest a workaround for now.
We found the dependency injection stuff with Spring really helpful, and we'd definitely use it again. The JDBC stuff made for cleaner DAO code, and probably our only complaint would be about the exceptions (not very many of them, and they're all runtime).
With Struts, using it definitely saved us time overall. That said, it did waste a lot of time at various points. When we were just getting started, we had loads of problems where a small typo of mis-configuration would cause the whole thing to fail to start, but without any errors. Loads of little things were we wasted time, just because the errors were either missing, incorrect or misleading.
ActionForwards in Struts are a very nifty idea. However, they're a huge pain to use when coupled with URL parameters. Using the struts html tag library to generate links with forwards, it's fairly easy to add a single URL parameter to a link (that said, the naming of the tag's attributes to trigger that are quite confusing). The moment you want more, you start having to faff with HashMaps, which is quite verbose in JSTL, so you end up with lengthy and ugly JSPs.
Adding URL parameters for ActionForwards in code is no easier. There ought to be a way, when defining an ActionForward in the XML, to specify what URL parameters it'll require, and which it'll take as optional. You could then set these nicely. As it is, you end up re-creating action forwards based on the previous one, and chucking bits onto the end of the path as required. A faff, and lacking in control.
Then we have ActionForms. Great, until you're dealing with a dynamically generated form (eg one name, one phone number, but as many addresses as you want, just keep hitting a JS button to spit more out). Completely fail at that point, and you end up just wandering the request parameters yourself.
Then we have the tags used with action forms. These suck badly - they really weren't designed with extensibility in mind. If you do try to extend one, you have to copy most of the code of the parent, because they just don't have extension points. If you want one tag to handle several form elements (eg take an Address object, and spit out one field for each line of the address), then you're not going to have a fun time :(
My overall conclusion would be - Sping=Very Good, Struts=Better than nothing, but quite wanting. I think if we were starting again, then we'd probably look into the spring view/controller stuff. As it is, we have helper methods to get round most of the struts annoyances, but they ideally shouldn't be needed :(