February 03, 2003
How do you like your Actions?
So, I've been doing research on struts and webwork. I started with struts because there seemed like there was more info on it, read the manning book, enjoyed it thoroughly now have delved into webwork. I must say that I like them both, though at this point if I had to choose, I'd probably go with webwork just because it seems a little more open ended and cleaner to use.
Along the way during my education, I came across two different Action models. Struts uses the Action/ActionForm mindset for separating data from Action and thats it. Which seemed like a good thing to me at first, I thought well why should the parameter data be tied into the action that uses it, its a good separation. Its kind of ugly seeing all that getter/setter in an Action that supposed to do logic.
Webwork allows you to do it 2 ways,but most of their examples tie data into the Action, theyre mindset being that the Action is basicly just a Javabean with an execute method, give or take for simplicitys sake. They also allow you to separate the data using a javabean via the Beanutils class and reflection which yields a result similiar to Struts' Action model.
So the more I think about it the more I wonder, which is the best way. Does anybody have any compelling arguments as to which they prefer? Or maybe they mix it up, depending upon the use of the data. I'm open to suggestion at this point but one situation which comes to mind that points to separation is the following:
If I wanted to have my Action take a bunch of user info from a form for later use during the session, and I had my data tied directly into the Action how would you go about putting that data in a beanlike way onto the session?
As per my current understanding, you'd have to populate a bean first,if you do that you may as well have started out with the separation,and toss the bean into the session, that was already populated. Unless there was some way to reference a previous Action's data on the property stack? like:
<ww:property value="MyAction/name"/>
where name is property on MyAction or something.
Posted by
Andre Mermegas
at
February 3, 2003 09:31 PM
|
TrackBack
This "session" saving stuff you're talking about is actually supported by WebWork. It's all done automatically. Never used it myself, but ping the mailing list. Jason Carriera is the one who wrote it originally. It might not even be in CVS right now, but I'm sure it's pretty trivial and could be added or you could write your own ActionFactoryProxy yourself that does this.
I love how Patrick says I did it and then says it's trivial :-)
Seriously, it was pretty trivial. It's not in CVS because I didn't want to slap another feature into WW 1.3 while we're trying to release it.
One thing I noticed while doing our Struts comparison is that the form bean separation in Struts is a red herring. In your action, you'll have to do a
MyActionFormType myAction = (MyActionFormType) form;
which is just tying your form bean implementation 1-1 with your action! At least in Webwork, if you wanted to, you could have a subproperty named myBean and name your form field vars myBean/prop1 and have them populated automatically without having to do this mapping. Webwork is just a lot more flexible in these respects, giving you lots of choices.
Note that recent versions of Struts support DynaBeans, which are an attempt to get away from the 1:1 mapping of Forms to actions, which I always found extraordinarily tedious myself.
Then again, you could look at Maverick (http://mav.sf.net/). It allows you to use any of the mentioned approaches. Look for different controllers in http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mav/maverick/src/java/org/infohazard/maverick/ctl/.
- FormBeanUser.java = The struts' way
- ThrowawayBean2.java = WebWork's way
- ThrowawayFormBeanUser.java = Hybrid approach
And if you ask me what implementation is the most clean, I would definitely say Maverick's. And Maverick is also truly open for any kind of view techonologies (WebWork is mostly JSP and Taglibs, so is Struts, althought there is some support for Velocity in both).
Personally, I get a little worried when an architecture asks you to build "noun" objects as distinct from "verb" objects. There may be specific reasons why it's OK to do this in a web framework specifically, but in general it's very un-OO. I personally don't like the "set, set, set, execute" JavaBean model, period... but it seems the rest of the world disagrees with me.