Apache Struts 2 Plugin Registry > Home > WebWork2 Plugin |
Name | WebWork2 Plugin |
---|---|
Publisher | Don Brown |
License | Open Source (ASL2) |
Version | 1.0-SNAPSHOT |
Compatibility | Struts 2.0.9+ |
Homepage | WebWork2 Plugin |
Download | SVN |
![]() | This plugin is only experimental and hasn't been released yet. It is not ready to be used in production applications. |
The Struts 2 WebWork plugin allows webwork actions and configuration to be used in Struts 2. It includes the necessary wrappers and adapters to allow a WebWork 2-based application to run in Struts 2 with minimal code changes.
If using Maven 2, replace the WebWork 2 dependency with this plugin, so change:
<dependency> <groupId>com.opensymphony</groupId> <artifactId>webwork</artifactId> <version>2.2.6</version> </dependency>
to:
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-webwork2-plugin</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
For other build systems, copy this plugin, Struts 2 jars, and any required plugin jars to your application's WEB-INF/lib directory.
The Struts FilterDispatch needs to be configured to read the webwork xwork configuration files. This can be done by adding init-params to the filter configuration:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml,xwork.xml</param-value>
</init-param>
<init-param>
<param-name>configProviders</param-name>
<param-value>org.apache.struts2.webwork2.WebWorkConfigurationProvider</param-value>
</init-param>
</filter>
The syntax of the struts tags are almost identical to the webwork tags. The webwork taglib can be replaced with the struts taglib. To do this, rename the struts-tags.tld from the struts core jar to webwork.tld and move this file into the WEB-INF directory of the war.
Struts requires a doctype if you have a validators.xml, add the following doctype:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator Config 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd">
Also, make sure you update the built in validators with the new validator classnames. The default validators can be found in the xwork source code at /com/opensymphony/xwork2/validator/validators/default.xml.
This plugin does not support webwork-style interceptors, so all interceptors must use Struts 2 Interceptor and ActionInvocation. Usually this only requires updating the package for these two interfaces.
This plugin does not support webwork-style ActionContext, so all Actions that use the Action context must be updated. Again, this is usually only requires updating the package for ActionContext.
Previously, an ActionMapper would be retrieved via the following code:
ActionMapper mapper = ActionMapperFactory.getMapper();
In Struts 2, the ActionMapper must be retreived via the internal Guice container:
Dispatcher du = Dispatcher.getInstance(); Configuration config = du.getConfigurationManager().getConfiguration(); ActionMapper mapper = config.getContainer().getInstance(ActionMapper.class);