About the Migration guide
The intent of this page is to provide a list of issue/resolutions as encountered while migrating from Struts 2.0.x to 2.1.x. The ultimate aim is to have a proper migration guide, but as 2.1.x is still evolving, any of the issue/resolutions found in this page may become obsolete any time.
Feel free to redraft material in this space! (That's why it's here!)
Migration issue/resolutions
The issues are listed in the same order as encountered after changing jars over from 2.0.x to 2.0.1. 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:
Problem Symptom:
SEVERE: Exception starting filter struts2 Unable to load configuration. - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:370) ... Caused by: Error building results for action ScheduleJob in namespace - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:372) ... 30 more Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success' - result - file:/home/giaz/code/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/ WEB-INF/classes/struts.xml:40:50 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:616) ... 35 more
The struts.xml before:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect-action"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result> </action>
To resolve the issue modify the struts.xml action definition to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirectAction"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result> </action>
or to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect">ListDisplayOptimizationJobStatus.action</result> <result name="error" type="tiles">webui.requestFailed</result> </action>
Tiles 2.1.x plugin tiles.xml requires DOCTYPE:
Problem Symptom:
Nov 22, 2007 11:38:11 AM org.apache.tiles.impl.BasicTilesContainer init INFO: Initializing Tiles2 container. . . Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester error SEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found. org.xml.sax.SAXParseException: Document is invalid: no grammar found. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
This is due to the fact that Tiles 2.0.5 now turns validation on as default.
The tiles.xml page before:
<?xml version="1.0" encoding="ISO-8859-1" ?> <tiles-definitions/>
To resolve the issue simply add:
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> <tiles-definitions/>
<s:head theme="ajax"/> is obsolete, use different theme:
Problem Symptom:
Accessing any page that includes <s:head theme="ajax"/> produces the following error:
Nov 22, 2007 1:54:51 PM freemarker.log.JDK14LoggerFactory$JDK14Logger error SEVERE: Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl. The problematic instruction: ---------- ==> ${parameters.parseContent?string} [on line 45, column 26 in template/ajax/head.ftl] ---------- Java backtrace for programmers: ---------- freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
Use a different theme e.g. <s:head theme="xhtml" />
ajax ui tags were moved to 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:
SEVERE: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: /jsp/list/listOptimizationJobStatus.jsp(6,0) Attribute href invalid for tag div according to TLD at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
JSP before migration:
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="display" uri="http://displaytag.sf.net" %> <%@ taglib prefix="s" uri="/struts-tags"%> <s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /> <s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"> </s:div> <img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>
Resolution is to import and use struts-dojo-tags plugin instead:
<%@ page contentType="text/html; charset=UTF-8" language="java" %> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /> <sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"> </sx:div> <img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>
Note the use of remote div is now through the dojo plugin taglib sx. Other ui tags are also no longer available through the /struts-tags taglib but only through the /struts-dojo-tags taglib: datetimepicker and autocompleter.
User-defined converter (subclassing StrutsTypeConverter) will no longer be needed when using datetimepicker:
Problem Symptom: Your custom StrutsTypeConverter implementation does not longer work. 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.
<%@ taglib prefix="s" uri="/struts-tags"%> <s:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">
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 e.g.
<%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <sx:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">
Need to disable struts.devMode. This is not really a migration issue but rather seems a bug in 2.1.x:
Problem Symptom: You receive the following exception accessing a page:
WARNING: Could not find property [struts.valueStack] ognl.OgnlException: target is null for setProperty(null, "preventCache", [Ljava.lang.String;@5f262a85) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651) at ognl.ASTProperty.setValueBody(ASTProperty.java:101) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177) at ognl.SimpleNode.setValue(SimpleNode.java:246) at ognl.ASTChain.setValueBody(ASTChain.java:172)
Resolution is to change set devMode to false in struts.xml e.g.
from
<constant name="struts.devMode" value="true" />
to
<constant name="struts.devMode" value="false" />