craigmcc 2002/06/22 21:05:21 Modified: src/share/org/apache/struts/action ActionServlet.java Log: Define a new "convertHack" boolean init parameter for ActionServlet that restores strict Struts 1.0 compatibility if set to true for form bean properties of Java wrapper class types (like java.util.Integer). Current default behavior for invalid conversions is to return the configured default value (usually zero). Struts 1.0 returned null in these cases. Set the "convertHack" parameter to "true" if your application depends on this. PR: Bugzilla #7317 Submitted by: Artur Filipiak <artur.filipiak at gate.pl> Revision Changes Path 1.106 +52 -4 jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java Index: ActionServlet.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v retrieving revision 1.105 retrieving revision 1.106 diff -u -r1.105 -r1.106 --- ActionServlet.java 23 Jun 2002 03:59:34 -0000 1.105 +++ ActionServlet.java 23 Jun 2002 04:05:21 -0000 1.106 @@ -82,7 +82,16 @@ import javax.servlet.http.HttpSession; import javax.sql.DataSource; import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.beanutils.converters.BooleanConverter; +import org.apache.commons.beanutils.converters.ByteConverter; +import org.apache.commons.beanutils.converters.CharacterConverter; +import org.apache.commons.beanutils.converters.DoubleConverter; +import org.apache.commons.beanutils.converters.FloatConverter; +import org.apache.commons.beanutils.converters.IntegerConverter; +import org.apache.commons.beanutils.converters.LongConverter; +import org.apache.commons.beanutils.converters.ShortConverter; import org.apache.commons.collections.FastHashMap; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; @@ -187,6 +196,11 @@ * servlet or JSP page. [text/html] * <em>DEPRECATED - Configure this using the "contentType" attribute * of the <controller> element.</em></li> + * <li><strong>convertHack</strong> - Set to <code>true</code> to force form + * bean population of bean properties that are of Java wrapper class types + * (such as java.lang.Integer) to set the property to <code>null</code>, + * instead of zero, in a manner equivalent to the behavior of Struts 1.0. + * [false]</li> * <li><strong>debug</strong> - The debugging detail level for this * servlet, which controls how much information is logged. Accepts * values 0 (off) and 1 (least serious) through 6 (most serious). [0]</li> @@ -296,6 +310,13 @@ /** + * The flag to request backwards-compatible conversions for form bean + * properties of the Java wrapper class types. + */ + protected boolean convertHack = false; + + + /** * The JDBC data sources that has been configured for this application, * if any, keyed by the servlet context attribute under which they are * stored. @@ -1066,6 +1087,33 @@ detail = Integer.parseInt(value); } catch (Throwable t) { detail = 0; + } + + // Backwards compatibility hack for form beans of Java wrapper classes + // Set to true for strict Struts 1.0 compatibility + value = getServletConfig().getInitParameter("convertHack"); + if (value != null) { + if ("true".equalsIgnoreCase(value) || + "yes".equalsIgnoreCase(value) || + "on".equalsIgnoreCase(value) || + "y".equalsIgnoreCase(value) || + "1".equalsIgnoreCase(value)) { + convertHack = true; + } else { + convertHack = false; + } + } + if (convertHack) { + ConvertUtils.deregister(); + ConvertUtils.register(new BooleanConverter(null), Boolean.class); + ConvertUtils.register(new ByteConverter(null), Byte.class); + ConvertUtils.register(new CharacterConverter(null), + Character.class); + ConvertUtils.register(new DoubleConverter(null), Double.class); + ConvertUtils.register(new FloatConverter(null), Float.class); + ConvertUtils.register(new IntegerConverter(null), Integer.class); + ConvertUtils.register(new LongConverter(null), Long.class); + ConvertUtils.register(new ShortConverter(null), Short.class); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>