Revision: 414
          http://svn.sourceforge.net/stripes/?rev=414&view=rev
Author:   tfenne
Date:     2006-09-25 19:16:32 -0700 (Mon, 25 Sep 2006)

Log Message:
-----------
Fix for STS-243: hidden tag does not output a tag if the value is null

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/tag/InputHiddenTag.java
    trunk/stripes/src/net/sourceforge/stripes/util/CollectionUtil.java

Added Paths:
-----------
    trunk/tests/src/net/sourceforge/stripes/util/CollectionUtilTest.java

Modified: trunk/stripes/src/net/sourceforge/stripes/tag/InputHiddenTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/InputHiddenTag.java   
2006-09-26 01:11:36 UTC (rev 413)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/InputHiddenTag.java   
2006-09-26 02:16:32 UTC (rev 414)
@@ -94,24 +94,26 @@
         Object valueOrValues = getOverrideValueOrValues();
 
         // Figure out how many times to write it out
-        if (valueOrValues != null) {
-            if (valueOrValues.getClass().isArray()) {
-                for (Object value : (Object[]) valueOrValues) {
-                    getAttributes().put("value", format(value));
-                    writeSingletonTag(getPageContext().getOut(), "input");
-                }
+        if (valueOrValues == null) {
+            getAttributes().put("value", "");
+            writeSingletonTag(getPageContext().getOut(), "input");
+        }
+        else if (valueOrValues.getClass().isArray()) {
+            for (Object value : (Object[]) valueOrValues) {
+                getAttributes().put("value", format(value));
+                writeSingletonTag(getPageContext().getOut(), "input");
             }
-            else if (valueOrValues instanceof Collection) {
-                for (Object value : (Collection) valueOrValues) {
-                    getAttributes().put("value", format(value));
-                    writeSingletonTag(getPageContext().getOut(), "input");
-                }
-            }
-            else {
-                getAttributes().put("value", format(valueOrValues));
+        }
+        else if (valueOrValues instanceof Collection) {
+            for (Object value : (Collection) valueOrValues) {
+                getAttributes().put("value", format(value));
                 writeSingletonTag(getPageContext().getOut(), "input");
             }
         }
+        else {
+            getAttributes().put("value", format(valueOrValues));
+            writeSingletonTag(getPageContext().getOut(), "input");
+        }
 
         // Clear out the value from the attributes
         getAttributes().remove("value");

Modified: trunk/stripes/src/net/sourceforge/stripes/util/CollectionUtil.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/CollectionUtil.java  
2006-09-26 01:11:36 UTC (rev 413)
+++ trunk/stripes/src/net/sourceforge/stripes/util/CollectionUtil.java  
2006-09-26 02:16:32 UTC (rev 414)
@@ -41,4 +41,18 @@
 
         return false;
     }
+
+    /**
+     * Checks to see if the array contains any values that are non-null non 
empty-string values.
+     * If it does, returns false.  Returns true for null arrays and zero 
length arrays, as well
+     * as for arrays consisting only of nulls and empty strings.
+     */
+    public static boolean empty(String[] arr) {
+        if (arr == null || arr.length == 0) return true;
+        for (String s : arr) {
+            if (s != null && !"".equals(s)) return false;
+        }
+
+        return true;
+    }
 }

Added: trunk/tests/src/net/sourceforge/stripes/util/CollectionUtilTest.java
===================================================================
--- trunk/tests/src/net/sourceforge/stripes/util/CollectionUtilTest.java        
                        (rev 0)
+++ trunk/tests/src/net/sourceforge/stripes/util/CollectionUtilTest.java        
2006-09-26 02:16:32 UTC (rev 414)
@@ -0,0 +1,46 @@
+package net.sourceforge.stripes.util;
+
+import org.testng.annotations.Test;
+import org.testng.Assert;
+
+/**
+ * Tests for the CollectionUtil class
+ *
+ * @author Tim Fennell
+ */
+public class CollectionUtilTest {
+    @Test(groups="fast")
+    public void testEmptyOnNullCollection() {
+        Assert.assertTrue(CollectionUtil.empty(null));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyOnCollectionOfNulls() {
+        Assert.assertTrue(CollectionUtil.empty(new String[] {null, null, 
null}));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyZeroLengthCollection() {
+        Assert.assertTrue(CollectionUtil.empty(new String[] {}));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyOnCollectionOfEmptyStrings() {
+        Assert.assertTrue(CollectionUtil.empty(new String[] {"", null, ""}));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyOnNonEmptyCollection1() {
+        Assert.assertFalse(CollectionUtil.empty(new String[] {"", null, 
"foo"}));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyOnNonEmptyCollection2() {
+        Assert.assertFalse(CollectionUtil.empty(new String[] {"bar"}));
+    }
+
+    @Test(groups="fast")
+    public void testEmptyOnNonEmptyCollection3() {
+        Assert.assertFalse(CollectionUtil.empty(new String[] {"bar", "splat", 
"foo"}));
+    }
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to