Versions Compared

Key

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

Update nomenclature
Wiki Markup


{note}As of December, 2005 the Struts and WebWork teams have agreed to combine their efforts to create Struts Action 2.0. Struts Action 2.0 will be based on WebWork 2.2. Therefore this comparison is less relevant as the two communities cooperate more.{note}

h2. Feature Comparison

{table}
Feature \| Struts | SAFWebWork 1.x \| SAFWebWork 2.x
*Action classes* \| SAF 1.xStruts requires Action classes to extend an Abstract base class. This shows a common problem in SAFStruts 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 maymust implement the {{com.opensymphony.xwork.Action}} Interface, with a series of other Interfaces for other services, like in WebWork 1.x. SAFWebWork2 2 has its own ActionSupport baseto classimplement that implements these Interfaces.
*Threading Model* \| SAFStruts 1 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 1Struts Actions as any resources held must be thread-safe or access to them must be synchronized. \| SAF 2WebWork 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* \| SAFStruts 1 Actions have dependencies on Servlets because they are passed theget 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. \| SAF 2  Servlets may be used outside a Web context, but it's not a good fit for JMS, for instance. | WebWork Actions are not tied to the web or any container. SAFWebWork 2actions Actions 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 couplingtieing code to athe containerWeb. | ditto
*Testability* \| Many strategies have sprung up around testing SAFStruts 1 applications, but the major hurdle is the fact that SAF 1Struts Actions are so tightly coupledtied to the web (receiving a servlet environmentRequest and Response object). This often leads people to test SAF 1 Struts Actions inside a container, which is both slow and isNOT notUNIT trueTESTING. unitThere testing.is Aa Junit extension, : Struts TestCase ([http://strutstestcase.sourceforge.net/]), can use either mocks or Cactus. \| SAFWebWork 1 Actionsactions can be tested by  instantiating your Actionaction, setting the properties, and invoking {{execute}} or an alias. SAF 2's usuage of dependency injectionexecuting them | ditto, but the emphasis on Inversion of Control 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* \| SAFStruts 1 requires the use of a FormBeanFormBeans for inputevery formsform, necessitating either a lot of extra classes or the use of DynaBeans \| SAF 2, which are really just a workaround for the limitation of requiring FormBeans | WebWork 1.x 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. SAFWebWork 2also notallows only supports the FormBean pattern, it  allows ModelDriven Actions that can useas discussed in "[WW1:Populate Form Bean and access its value]" | WebWork 2 allows the same features as WebWork 1, but adds ModelDriven Actions, which allow you 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* \| SAFStruts 1.1 integrates with JSTL, so it uses the JSTL EL. TheThis EL has basic object graph traversal, but relatively weak collection and indexed property support. \| SAF 2 uses OGNL, a | 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 work with [JSTL] | WebWork uses [Ognl] which is a VERY powerful expression language, with additions for accessing the ValueStackvalue stack. 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). Ognl OGNLalso allows access to static methods, static fields, and constructors of classes. SAFWebWork2 2may can also use JSTL. JSTL as mentioned in [WW1:Using JSTL seamlessly with WebWork]
*Binding values into views* \| SAFStruts 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 2WebWork 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* \| SAFStruts 1 FormBeans properties are usually all Strings. SAFStruts 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. \| SAF 2 uses OGNL| WebWork 1.x uses PropertyEditors 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 SAFWW2 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 | SAFWebWork 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* \| SAFStruts 1 calls validate() on the FormBean. SAF 1Struts 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 manytypes of validations aremust perfomedeither bybe convertingduplicated input(checking andtype thenconversion) throwingor awaycannot thebe result. The SAF 1 validator candone? \\ \\ Can Commons Validation have different validation contexts for the same class? (I've been told yes, but it cannot so that's a good thing) \\ \\ Can Commons Validation chain to validations on sub-objects, using the validations defined for that object properties class? | WebWork1. \| SAFx 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) | WebWork can use athe {{validate}}() method orof WebWork and Struts and / or use the XWork [Validation] framework, which is activated using an XWork Interceptor. 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 classesclass. 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* \| SAF 1 provides a single request processor per module, which utilizes a uniforum lifecycle for each Action in a module. \| SAF 2 can specify request life cycles (Interceptor Stack)As far as I know Struts sets up the Action object for you, and you have very little control 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 Action 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 project