Table of Contents
- Update Dependencies
- Update Custom Type Converters
- Update struts.xml Configuration
- Migrate plugin configuration
- Convert EL expressions to OGNL
- Refactor usage of static methods via OGNL
- Reduce verbose logging
- Update Unit Tests
- Explicitly set the includeParams attribute on all url tags to "get" if it is not specified.
- Filter Mapping, default Action extensions, and Servlets
- Result type "redirect-action" was renamed to "redirectAction":
- Tiles 2.1.x plugin tiles.xml now requires DOCTYPE:
- <s:head theme="ajax"/> is obsolete, use a different theme:
- Ajax UI tags were moved to the new dojo plugin, use /struts-dojo-tags taglib instead of (or in addition to) /struts-tags:
- User-defined converter (subclassing StrutsTypeConverter) will no longer be needed when using datetimepicker:
Update your project dependences to use struts2-core-2.1.x and the plugins struts2-core-2.1.x.
Maven users can update their project's pom.xml to reference the new core and plugin versions. Ensure no dependencies in the
freemarker groupId are used as the latest version used by Struts is now under the
org.freeemarker groupId and will cause classpath conflicts.
If you need releases not considered General Availability you can use a staging repository where they are usually available:
Non-Maven users can can download the jars and dependencies in a Distribution 2.1.6
Update Custom Type Converters
If your project implements custom type converters you may need to change the imports statements to use the com.opensymphony.xwork2.conversion package. Failing to do so will cause a compile-time error.
Note: this may also affect conversion classes listed in the xwork-conversion.properties file.
Update struts.xml Configuration
Results and Interceptors have been renamed to use camelCase instead of hyphenated names (eg. now redirectAction instead of redirect-action).
Review all custom interceptor stacks, interceptor refs and results in struts.xml and remove the hyphen.
Migrate plugin configuration
If you use the Tiles 2 plugin, check your tiles.xml file(s) to ensure they contain a DOCTYPE.
Ajax Theme / Dojo
If your WebApp uses the ajax theme bundled with Struts 2.0 (ajax tags), you need to update every pageas the Dojo support has been moved into a separate plugin and tag library.
1. Add the Dojo plugin as a new dependency for your project
2. Modify ALL pages that use the ajax theme to use the Dojo tag library.
For each page there are three tasks to complete:
- reference the new Dojo tag library
- update the head tag
- update all ajax themed tags
- check inline scripts
- check inline widgets
Reference the new Dojo Tag Library
Reference the new taglib in your JSP or FTL pages.
Update the head tag
Review the new attributes of the new head tag. You need to decide which values for the cache, compressed, parseContent and extraLocales attributes are appropriate for your application. These settings have major performance implications.
Update all ajax themed tags
Some tags are available only in the Dojo plugin taglib. It will be immediately obvious from your IDE that these tags need to change to the sx: prefix.
Some tags are available in both the core and Dojo plugin taglibs. Any tag that uses the ajax theme needs to be changed to the sx: prefix.
eg. The following bind will execute scripts within the result when the Submit button is pressed
Check inline widgets
If your ajax html results include dojo widgets, ensure the head tag's parseContent attribute is true. This instructs dojo to parse the ajax responses for widgets. Note that Struts2.0 always enabled this feature and it could not be turned off. Struts2.1 disables this feature and allows it to be turned on as there is a significant performance impact.
Convert EL expressions to OGNL
Struts2.1 tags do not allow evaluation of JSP EL within their attributes. Instead, Struts2 tags evaluate attribute values as OGNL. Allowing both expression languages within the same attribute opens major security vulnerabilities.
todo: how to convert
Refactor usage of static methods via OGNL
The default behaviour of allowing access to static methods (via an expression like "@org.somewhere.FooUtls@fooMethod()") has been disabled for security reasons in the 2.1 branch. See https://issues.apache.org/struts/browse/WW-2160 for details. You should either remove these cases, or re-enable the use of static methods explicitly in your configuration by using the struts.ognl.allowStaticMethodAccess property.
Reduce verbose logging
Struts 2.1 introduces more verbose logging than Struts 2.0. While extremely valuable, some users may find these annoying.
This message states that the framework searched for a property in the value stack and failed to find it.
To hide these messages, turn off the WARN level logging for OgnlValueStack.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
TextProvider missing keys
These messages state that the framework searched for text in a resource bundle and failed to find it.
To hide those messages, turn off the WARN level logging for TextProviderHelper.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
Redirect and RedirectAction parameters
A (incorrect) change in 2.1.6 has ObjectFactory reporting ERROR's when you attempt to set parameters on a Redirect result.
So a redirect result that sets a parameter like this:
Will always give you an error like this:
You can safely ignore and suppress the error by setting the logging level to 'fatal' like this:
Update Unit Tests
There are two known major migration issues affecting user's unit tests.
- The Configuration API now uses a Builder pattern
- The ActionContext.getContext() method does not create a context on demand.
Review the Unit Tests included with Struts2 for recommended practices to setup the Configuration and context.
A quick fix for ActionContext.getContext() returning
Explicitly set the includeParams attribute on all url tags to "get" if it is not specified.
The default value of this attribute changed from "get" to "none". See https://issues.apache.org/struts/browse/WW-2901
Filter Mapping, default Action extensions, and Servlets
The default action extension list (struts.action.extension) has changed from just 'action' to 'action' plus "" (no extension). If your application has servlets or other requests that have no extension then they will be mistaken as actions and you will get a "There is no Action mapped for ..." exception like below.
To fix this problem you can explicitly set the default action extension back to just "action" or you can change your filter mapping for the struts filter.
To set the action extension list back to just "action" add this to your struts.xml file:
If all your actions use the ".action" suffix then you may want to change the Struts filter-mapping so that only actions are handled by the struts filter. Also the FilterDispatcher has been deprecated and replaced by StrutsPrepareAndExecuteFilter.
The web.xml before (matching all requests):
Change to use the new StrutsPrepareAndExecuteFilter and match just struts requests.
The web.xml after:
The issues are listed in the same order as encountered after changing jars over from 2.0.x to 2.1.x. Noteworthy, the migration was done under the following setup: Fedora core 6, JDK 1.6.0_2 and Tomcat 6.0.10 running from MyEclipse plugin.
Result type "redirect-action" was renamed to "redirectAction":
The struts.xml before:
To resolve this issue modify the struts.xml action definition to:
Tiles 2.1.x plugin tiles.xml now requires DOCTYPE:
The tiles.xml page before:
To resolve the issue simply add:
<s:head theme="ajax"/> is obsolete, use a different theme:
Problem Symptom: Accessing any page that includes <s:head theme="ajax"/> produces the following error:
Resolution is to either remove the "<s:head theme="ajax"/>" or use a different theme e.g. <s:head theme="xhtml" />
Ajax UI tags were moved to the new dojo plugin, use /struts-dojo-tags taglib instead of (or in addition to) /struts-tags:
Problem Symptom: Accessing a page containing ajax UI tags through using the struts 2 taglib will produce the following error:
JSP before migration:
Resolution is to import and use struts-dojo-tags plugin instead:
User-defined converter (subclassing StrutsTypeConverter) will no longer be needed when using datetimepicker:
Problem Symptom: Your custom StrutsTypeConverter implementation does not longer work in version 2.1.x. In 2.0.x you needed to implement a custom StrutsTypeConverter e.g. StringToDateConverter to be able to parse and convert to Date the String posted from a datetimepicker control into the action. In version 2.0.x datetimepicker was posting a String formatted as specified in the "displayFormat" field e.g.
In version 2.1.x datetimepicker will post a String Date in RFC 3339 format, so you can define your setter to receive a Date directly and avoid using converters for this purpose e.g.
Parameters set by the action mapping are not set/not available through ParameterAware (This change is only needed when going to 2.1.x (where x>0))
These are now only available if you use the new interceptor named "actionMappingParams".