Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Update nomenclature
Wiki Markup


h2. Feature Comparison

{table}
Feature \| StrutsSAF | WebWork 1.x \| WebWorkSAF 2.x
*Action classes* \| SAF Struts1.x requires Action classes to extend an Abstract base class. This shows a common problem in StrutsSAF 1 of programming to abstract classes instead of interfaces. | Action classes must implement the webwork.Action Interface. There are other Interfaces which can be implemented for other services, such as storing error messages, getting localized texts, etc. The ActionSupport class implements many of these Interfaces and can act as a base class. WebWork is all written to Interfaces, which allows for plugging in your own implementations.| \| An Action mustmay implement the {{com.opensymphony.xwork.Action}} Interface, with a series of other Interfaces for other services, like in WebWork 1.x. SAF WebWork22 has its own ActionSupport to implementbase class that implements these Interfaces.
*Threading Model* \| SAF Struts1 Actions must be thread-safe because there will only be one instance to handle all requests. This places restrictions on what can be done with SAF Struts1 Actions as any resources held must be thread-safe or access to them must be synchronized. \| WebWorkSAF 2 Actions are instantiated for each request, so there are no thread-safety issues. In practice, Servlet containers generate many throw-away objects per request, and one more Objectobject does not prove to be a problem for performance or garbage collection. | ditto
*Servlet Dependency* \| StrutsSAF 1 Actions have dependencies on Servlets because they getare passed the ServletRequest and ServletResponse (not HttpServletRequest and HttpServletResponse, I've been told) when they are executed. This\| tie to Servlets (although not Http*) is a defacto tie to a Servlet container, which is an unneeded dependency. Servlets may be used outside a Web context, but it's not a good fit for JMS, for instance. | WebWork SAF 2 Actions are not tied to the web or any container. SAF WebWork2 actionsActions CAN choose to access the request and response from the ActionContext, but it is not required and should be done only when ABSOLUTELY neccessary to avoid tieingcoupling code to thea Webcontainer. | ditto
*Testability* \| Many strategies have sprung up around testing SAF Struts1 applications, but the major hurdle is the fact that SAF Struts1 Actions are socoupled tightly tied to the web (receiving a Request and Response object)servlet environment. This often leads people to test SAF 1 Struts Actions inside a container, which is both slow and NOTis UNITnot TESTING.true Thereunit istesting. aA Junit extension, : Struts TestCase ([http://strutstestcase.sourceforge.net/]), can use either mocks or Cactus. \| WebWorkSAF 1 actionsActions can be tested by  instantiating your actionAction, setting the properties, and executing them | ditto, but the emphasis on Inversion of Controlinvoking {{execute}} or an alias. SAF 2's usuage of dependency injection makes testing even simpler, as you can just set a Mock implementation of your services into your Action for testing, instead of having to set up service registries or static singletons
*FormBeans* \| SAF Struts1 requires the use of FormBeansa FormBean for everyinput formforms, necessitating either a lot of extra classes or the use of DynaBeans, which are really just a workaround for the limitation of requiring FormBeans | WebWork 1.x \| SAF 2 allows you to have all of your properties directly accessible on your Action as regular Javabeans properties, including rich Object types which can have their own properties which can be accessed from the web page. WebWork also allowsSAF 2 not only supports the FormBean pattern, asit discussed in "[WW1:Populate Form Bean and access its value]" | WebWork 2 allows the same features as WebWork 1, but adds ModelDriven Actions, whichthat allowcan youuse to have a rich Object type or domain object as your form bean, with its properties directly accessible to the web page, rather than accessing them as sub-properties of a property of the Action.
*Expression Language* \| StrutsSAF 1.1 integrates with JSTL, so it uses the JSTL EL. ThisThe EL has basic object graph traversal, but relatively weak collection and indexed property support.  | WebWork 1.x has its own Expression language which is built for accessing the ValueStack. Collection and indexed property support are basic but good. WebWork can also be made to work directly with JSTL using the Filter described in [WW1:Using JSTL seamlessly with WebWork] | WebWork\| SAF 2 uses [XW:Ognl] which isOGNL, a VERY powerful expression language, with additions for accessing the value stackValueStack. OgnlOGNL supports very powerful collection and indexed property support. OgnlOGNL also supports powerful features like projections (calling the same method on each member of a collection and building a new collection of the results), selections (filtering a collection with a selector expression to return a subset), list construction, and lambda expressions (simple functions which can be reused). OgnlOGNL also allows access to static methods, static fields, and constructors of classes. SAF WebWork22 maycan also use JSTL as mentioned in [WW1:Using JSTL seamlessly with WebWork].
*Binding values into views* \| StrutsSAF 1 uses the standard JSP mechanism for binding objects into the page context for access, which tightly couples your view to the form beans being rendered \| SAF WebWork2 sets up a ValueStack which the WebWork taglibs access to dynamically find values very flexibly without tightly coupling your view to the types it is rendering. This strategy allows you to reuse views across a range of types which have the same properties. | ditto
*Type Conversion* \| SAF Struts1 FormBeans properties are usually all Strings. StrutsSAF 1 uses Commons-Beanutils for type conversion. Converters are per-class, and not configurable per instance. Getting a meaningful type conversion error out and displaying it to the user can be difficult. \| WebWorkSAF 1.x2 uses PropertyEditorsOGNL for type conversion. PropertyEditors are per type and not settable per Action, but field error messages are added to the field error map in the Action to be automatically displayed to the user with the field. | WebWork2 uses Ognl for type conversion with added converters provided for all basic types. Type converters default to these converters, but type conversion can be specified per field per class. Type conversion errors also have a default error message but can be set per field per class using the localization mechanism in WW2SAF 2 and will be set into the field error messages of the Action.
*Modular Before & After Processing* \| Class hierarchies of base Actions must be built up to do processing before and after delegating to the Action classes, which can lead deep class hierarchies and limitations due to the inability to have multiple inheritance _[WW:Comparison to Struts#1]_ \| Class hierarchies | WebWork SAF 2 allows you to modularize before and after processing in Interceptors. Interceptors can be applied dynamically via the configuration without any coupling between the Action classes and the Interceptors. 
*Validation* \| SAF Struts1 calls validate() on the FormBean. StrutsSAF 1 users often use Commons Validation for validation. I don't know a lot about this, so I'll put some questions here: \\ \\ Because FormBean properties are usually Strings, some typesmany of validations mustare eitherperfomed beby duplicatedconverting (checkinginput typeand conversion)then orthrowing cannotaway bethe done? \\ \\ Can Commons Validationresult. The SAF 1 validator can have different validation contexts for the same class? (I've been told yes, sobut that's a good thing) \\ \\ Can Commons Validation it cannot chain to validations on sub-objects, using the validations defined for that object properties class? | WebWork1.x calls the validate() method on Actions, which can either do programmatic validations or call an outside validation framework (this is apparently the same as Struts) | WebWork2 \| SAF can use thea {{validate()}} method of WebWork and Struts and / or or use the [XW:Validation Framework], which is activated using an XWork InterceptorXWork Validation framework. The XworkXWork Validation Framework allows you to define validations in an XML format with default validations for a class and custom validations added for different validation contexts. The XworkXWork Validation Framework is enabled via an Interceptor and is therefore completely decoupled from your Action classclasses. The XworkXWork Validation Framework also allows you to chain the validation process down into sub-properties using the VisitorFieldValidator which will use the validations defined for the properties class type and the validation context.
*Control Of Action Execution* \| AsSAF far1 asprovides Ia knowsingle Strutsrequest setsprocessor up the Action object for youper module, andwhich youutilizes havea veryuniforum littlelifecycle controlfor over the order of operations. To change them I think (?) you need to write your own Servlet to handle dispatching as you want | The ActionFactory chain controls the order in which an Action is constructed and initialised, but this requires writing a class | The interceptor stacks in WebWork 2 are hugely powerful in this regard. All aspects of Action setup have been moved into Interceptor implementations (ie setting paramters from the web, validation etc), so you can control on a per action basis the order in which they are performed. For example you might want your IOC framework to setup the action before the parameters are set from the request or vice versa - you can thusly control this on a per package or per action basis with interceptor stacks. 
{table}

h2. References

* http://www.mail-archive.com/opensymphony-webwork@lists.sourceforge.net/msg00995.html - compares Struts development to WebWork 1.x development from the point of view of a Stuts developer who switched to WebWork
* http://www.mail-archive.com/opensymphony-webwork@lists.sourceforge.net/msg04700.html - Kind of the first draft of this comparison

h2. Footnotes
# {anchor:1} Some Stuts users have built the beginnings of an Interceptor framework for Struts (http://struts.sourceforge.net/saif/). It currently has some serious limitations (no "around" processing, just before and after) and is not part of the main Struts projecteach Action in a module. \| SAF 2 can specify request life cycles (Interceptor Stack) on a per Action basis. 
{table}