craigmcc 02/03/15 19:00:44 Modified: doc/userGuide struts-logic.xml src/share/org/apache/struts/taglib/logic CompareTagBase.java web/exercise-taglib logic-compare.jsp Log: Relax the comparison rules so that a null variable will be coerced to a zero-length string before being compared to the specified value. This avoids a lot of cases where <logic:present> type tags were necessary to deal with null values. This is an upwards-compatible enhancement for 1.0 (the old behavior was to throw an exception, so nobody was able to write a page that used null properties before), so I'm going to port the change to 1.0.x as well. PR: Bugzilla #6409 Submitted by: Ovidiu Podisor <opodisor at websitepros.com> Revision Changes Path 1.2 +2 -2 jakarta-struts/doc/userGuide/struts-logic.xml Index: struts-logic.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-logic.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- struts-logic.xml 20 Feb 2002 00:41:14 -0000 1.1 +++ struts-logic.xml 16 Mar 2002 03:00:44 -0000 1.2 @@ -33,8 +33,8 @@ <code>name</code>, <code>parameter</code>, <code>property</code>) present on this tag. It will be converted to the appropriate type for the comparison, as determined above.</li> - <li>A request time exception will be thrown if the specified variable - cannot be retrieved, or has a null value.</li> + <li>If the specified variable or property returns null, it will be + coerced to a zero-length string before the comparison occurs.</li> <li>The specific comparison for this tag will be performed, and the nested body content of this tag will be evaluated if the comparison returns a <code>true</code> result.</li> 1.8 +5 -8 jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java Index: CompareTagBase.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CompareTagBase.java 16 Jul 2001 00:44:56 -0000 1.7 +++ CompareTagBase.java 16 Mar 2002 03:00:44 -0000 1.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java,v 1.7 2001/07/16 00:44:56 craigmcc Exp $ - * $Revision: 1.7 $ - * $Date: 2001/07/16 00:44:56 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java,v 1.8 2002/03/16 03:00:44 craigmcc Exp $ + * $Revision: 1.8 $ + * $Date: 2002/03/16 03:00:44 $ * * ==================================================================== * @@ -78,7 +78,7 @@ * define values for desired1 and desired2. * * @author Craig R. McClanahan - * @version $Revision: 1.7 $ $Date: 2001/07/16 00:44:56 $ + * @version $Revision: 1.8 $ $Date: 2002/03/16 03:00:44 $ */ public abstract class CompareTagBase extends ConditionalTagBase { @@ -253,10 +253,7 @@ throw e; } if (variable == null) { - JspException e = new JspException - (messages.getMessage("logic.variable", value)); - RequestUtils.saveException(pageContext, e); - throw e; + variable = ""; // Coerce null to a zero-length String } // Perform the appropriate comparison 1.5 +65 -32 jakarta-struts/web/exercise-taglib/logic-compare.jsp Index: logic-compare.jsp =================================================================== RCS file: /home/cvs/jakarta-struts/web/exercise-taglib/logic-compare.jsp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- logic-compare.jsp 4 May 2001 21:49:31 -0000 1.4 +++ logic-compare.jsp 16 Mar 2002 03:00:44 -0000 1.5 @@ -390,38 +390,6 @@ </td> </tr> <tr> - <td>string / EQ</td> - <td><bean:write name="bean" property="stringProperty"/></td> - <td><%= str1 %></td> - <td>equal greaterEqual lessEqual</td> - <td> - <logic:equal name="bean" property="stringProperty" - value="<%= str1 %>"> - equal - </logic:equal> - <logic:greaterEqual name="bean" property="stringProperty" - value="<%= str1 %>"> - greaterEqual - </logic:greaterEqual> - <logic:greaterThan name="bean" property="stringProperty" - value="<%= str1 %>"> - greaterThan - </logic:greaterThan> - <logic:lessEqual name="bean" property="stringProperty" - value="<%= str1 %>"> - lessEqual - </logic:lessEqual> - <logic:lessThan name="bean" property="stringProperty" - value="<%= str1 %>"> - lessThan - </logic:lessThan> - <logic:notEqual name="bean" property="stringProperty" - value="<%= str1 %>"> - notEqual - </logic:notEqual> - </td> - </tr> - <tr> <td>long / EQ</td> <td><bean:write name="bean" property="longProperty"/></td> <td><%= long1 %></td> @@ -614,6 +582,38 @@ </td> </tr> <tr> + <td>string / EQ</td> + <td><bean:write name="bean" property="stringProperty"/></td> + <td><%= str1 %></td> + <td>equal greaterEqual lessEqual</td> + <td> + <logic:equal name="bean" property="stringProperty" + value="<%= str1 %>"> + equal + </logic:equal> + <logic:greaterEqual name="bean" property="stringProperty" + value="<%= str1 %>"> + greaterEqual + </logic:greaterEqual> + <logic:greaterThan name="bean" property="stringProperty" + value="<%= str1 %>"> + greaterThan + </logic:greaterThan> + <logic:lessEqual name="bean" property="stringProperty" + value="<%= str1 %>"> + lessEqual + </logic:lessEqual> + <logic:lessThan name="bean" property="stringProperty" + value="<%= str1 %>"> + lessThan + </logic:lessThan> + <logic:notEqual name="bean" property="stringProperty" + value="<%= str1 %>"> + notEqual + </logic:notEqual> + </td> + </tr> + <tr> <td>string / GT</td> <td><bean:write name="bean" property="stringProperty"/></td> <td><%= str2 %></td> @@ -677,7 +677,40 @@ </logic:notEqual> </td> </tr> + <tr> + <td>string / NULL</td> + <td><bean:write name="bean" property="nullProperty"/> </td> + <td> </td> + <td>equal greaterEqual lessEqual</td> + <td> + <logic:equal name="bean" property="nullProperty" + value=""> + equal + </logic:equal> + <logic:greaterEqual name="bean" property="nullProperty" + value=""> + greaterEqual + </logic:greaterEqual> + <logic:greaterThan name="bean" property="nullProperty" + value=""> + greaterThan + </logic:greaterThan> + <logic:lessEqual name="bean" property="nullProperty" + value=""> + lessEqual + </logic:lessEqual> + <logic:lessThan name="bean" property="nullProperty" + value=""> + lessThan + </logic:lessThan> + <logic:notEqual name="bean" property="nullProperty" + value=""> + notEqual + </logic:notEqual> + </td> + </tr> </table> + </body> </html>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>