Commits

Anonymous committed b3432e9

Partially fixed double select tag. Still need to test preset value(s) and set values. Phew, goddamn complex script.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@614573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits cd4e4a5

Comments (0)

Files changed (7)

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractDoubleListTag.java

     protected String doubleListValueAttr;
     protected String doubleNameAttr;
     protected String doubleValueAttr;
+    protected String formNameAttr;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         this.doubleValueAttr = doubleValue;
     }
 
+    public void setFormName(String formName) {
+        this.formNameAttr = formName;
+    }
+
     public void evaluateExtraParams(OgnlValueStack stack) {
         super.evaluateExtraParams(stack);
 
         Object doubleName = null;
 
         if (doubleNameAttr != null) {
-            doubleName = findString(doubleNameAttr);
-            addParameter("doubleName", doubleName);
+            addParameter("doubleName", findString(doubleNameAttr));
         }
 
         if (doubleListAttr != null) {
             addParameter("doubleListValue", doubleListValueAttr);
         }
 
+        if (formNameAttr != null) {
+            addParameter("formName", findString(formNameAttr));
+        }
+
         Class valueClazz = getValueClassType();
 
         if (valueClazz != null) {

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractListTag.java

 
 import java.util.Collection;
 import java.util.Map;
+import java.lang.reflect.Array;
 
 
 /**
         if (listAttr != null) {
             if (value instanceof Collection) {
                 addParameter("list", value);
-                addParameter("listSize", new Integer(((Collection) value).size()));
             } else {
                 addParameter("list", MakeIterator.convert(value));
             }
+
+            if (value instanceof Collection) {
+                addParameter("listSize", new Integer(((Collection) value).size()));
+            } else if (value instanceof Map) {
+                addParameter("listSize", new Integer(((Map) value).size()));
+            } else if (value.getClass().isArray()) {
+                addParameter("listSize", new Integer(Array.getLength(value)));
+            }
         }
 
         if (listKeyAttr != null) {

src/java/template/simple/doubleselect.vm

-#parse("/template/xhtml/controlheader.vm")
-
 <select name="$!webwork.htmlEncode($parameters.name)"
-    #if ($parameters.size)             size="$!webwork.htmlEncode($parameters.size)"         #end
-    #if ($parameters.disabled)         disabled="disabled"                                   #end
-    #if ($parameters.tabindex)         tabindex="$!webwork.htmlEncode($parameters.tabindex)" #end
-    #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"             #end
-    #if ($parameters.multiple)         multiple="multiple"                                   #end
-    #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"    #end
-    #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"    #end
-    onchange="$!{parameters.name}Redirect(this.options.selectedIndex)"
->
+    #if ($parameters.size)             size="$!webwork.htmlEncode($parameters.size)"               #end
+    #if ($parameters.disabled)         disabled="disabled"                                         #end
+    #if ($parameters.tabindex)         tabindex="$!webwork.htmlEncode($parameters.tabindex)"       #end
+    #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                   #end
+    #if ($parameters.multiple)         multiple="multiple"                                         #end
+    #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"          #end
+    #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"          #end
+    #if ($parameters.onclick)          onclick="$!webwork.htmlEncode($parameters.onclick)"         #end
+    #if ($parameters.ondblclick)       ondblclick="$!webwork.htmlEncode($parameters.ondblclick)"   #end
+    #if ($parameters.onmousedown)      onmousedown="$!webwork.htmlEncode($parameters.onmousedown)" #end
+    #if ($parameters.onmouseup)        onmouseup="$!webwork.htmlEncode($parameters.onmouseup)"     #end
+    #if ($parameters.onmouseover)      onmouseover="$!webwork.htmlEncode($parameters.onmouseover)" #end
+    #if ($parameters.onmousemove)      onmousemove="$!webwork.htmlEncode($parameters.onmousemove)" #end
+    #if ($parameters.onmouseout)       onmouseout="$!webwork.htmlEncode($parameters.onmouseout)"   #end
+    #if ($parameters.onfocus)          onfocus="$!webwork.htmlEncode($parameters.onfocus)"         #end
+    #if ($parameters.onblur)           onblur="$!webwork.htmlEncode($parameters.onblur)"           #end
+    #if ($parameters.onkeypress)       onkeypress="$!webwork.htmlEncode($parameters.onkeypress)"   #end
+    #if ($parameters.onkeydown)        onkeydown="$!webwork.htmlEncode($parameters.onkeydown)"     #end
+    #if ($parameters.onkeyup)          onkeyup="$!webwork.htmlEncode($parameters.onkeyup)"         #end
+    #if ($parameters.onselect)         onselect="$!webwork.htmlEncode($parameters.onselect)"       #end
+    onchange="$!{parameters.name}Redirect(this.options.selectedIndex)">
 
 #set ( $startCount = 0)
 #if ($parameters.headerKey && $parameters.headerValue)
 #if( $items )
     #foreach( $item in $items )
         $stack.push($item)
-
         #if( $parameters.listKey )
             #set( $itemKey = $stack.findValue($parameters.listKey) )
         #else
             #set( $itemKey = $item )
         #end
-
         #if( $parameters.listValue )
             #set( $itemValue  = $stack.findValue($parameters.listValue) )
         #else
             #set( $itemValue = $item )
         #end
-
-        <option value="$!webwork.htmlEncode($itemKey)"
-            #if( $tag.contains($parameters.nameValue, $itemKey) )selected="selected"#end
-        >$!webwork.htmlEncode($itemValue)</option>
-
+        <option value="$!webwork.htmlEncode($itemKey)"#if( $tag.contains($parameters.nameValue, $itemKey) ) selected="selected"#end>$!webwork.htmlEncode($itemValue)</option>
         #set ($trash = $stack.pop())
     #end
 #end
 </select>
-
 <br/>
-
 <select name="$!webwork.htmlEncode($parameters.doubleName)"
+    #if ($parameters.disabled)         disabled="disabled"                                         #end
     #if ($parameters.doubleTabindex)   tabindex="$!webwork.htmlEncode($parameters.doubleTabindex)" #end
     #if ($parameters.doubleId)         id="$!webwork.htmlEncode($parameters.doubleId)"             #end
     #if ($parameters.multiple)         multiple="multiple"                                         #end
     #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"          #end
 >
 </select>
-
 <script type="text/javascript">
-<!--
 #set( $itemCount = $startCount )
-var $!{parameters.name}Group = new Array($items.size() + $startCount)
-for (i = 0; i < ($items.size() + $startCount); i++)
-$!{parameters.name}Group[i] = new Array()
-
+var $!{parameters.name}Group = new Array($!{parameters.listSize} + $startCount);
+for (i = 0; i < ($!{parameters.listSize} + $startCount); i++)
+$!{parameters.name}Group[i] = new Array();
 #foreach( $item in $items )
     $stack.push($item)
-
     #if( $parameters.listKey )
         #set( $itemKey = $stack.findValue($parameters.listKey) )
     #else
         #set( $itemKey = $item )
     #end
-
     #if( $parameters.listValue )
         #set( $itemValue  = $stack.findValue($parameters.listValue) )
     #else
         #set( $itemValue = $item )
     #end
-
     #set( $doubleItems = $stack.findValue($parameters.doubleList) )
     #set( $doubleItemCount = 0 )
-
     #if( $doubleItems )
         #foreach( $doubleItem in $doubleItems )
+            $stack.push($doubleItem)
             #if( $parameters.doubleListKey )
                 #set( $doubleItemKey = $stack.findValue($parameters.doubleListKey) )
             #else
                 #set( $doubleItemKey = $doubleItem )
             #end
-
             #if( $parameters.doubleListValue )
                 #set( $doubleItemValue  = $stack.findValue($parameters.doubleListValue) )
             #else
                 #set( $doubleItemValue = $doubleItem )
             #end
-
-            $!{parameters.name}Group[$itemCount][$doubleItemCount] = new Option("$doubleItemKey", "$doubleItemValue")
+            $!{parameters.name}Group[$itemCount][$doubleItemCount] = new Option("$doubleItemKey", "$doubleItemValue");
             #set( $doubleItemCount = $doubleItemCount + 1 )
+            #set ($trash = $stack.pop())
         #end
-
         #set( $itemCount = $itemCount + 1 )
     #end
-
     #set ($trash = $stack.pop())
 #end
-
-## CHANGE THE NAME OF YOUR FORM HERE, NEED TO FIX THIS
-var $!{parameters.name}Temp = document.$!{parameters.form.name}.$!{parameters.doubleName}
-
+var $!{parameters.name}Temp = document.$!{parameters.formName}.$!{parameters.doubleName};
 #set( $itemCount = $startCount )
 #set( $redirectTo = 0 )
 #foreach( $item in $items )
     $stack.push($item)
-
     #if( $parameters.listValue )
         #set( $itemValue  = $stack.findValue($parameters.listValue) )
     #else
         #set( $itemValue = $item )
     #end
-
     #if( $tag.contains($parameters.nameValue, $itemKey) )
         #set( $redirectTo = $itemCount )
     #end
     #set( $itemCount = $itemCount + 1 )
-
     #set ($trash = $stack.pop())
 #end
-
-$!{parameters.name}Redirect($redirectTo)
-
+$!{parameters.name}Redirect($redirectTo);
 function $!{parameters.name}Redirect(x) {
     for (m = $!{parameters.name}Temp.options.length - 1; m >= 0; m--)
-        $!{parameters.name}Temp.options[m] = null
+        $!{parameters.name}Temp.options[m] = null;
 
     for (i = 0; i < $!{parameters.name}Group[x].length; i++) {
-        $!{parameters.name}Temp.options[i] = new Option($!{parameters.name}Group[x][i].text, $!{parameters.name}Group[x][i].value)
+        $!{parameters.name}Temp.options[i] = new Option($!{parameters.name}Group[x][i].text, $!{parameters.name}Group[x][i].value);
     }
 
     if ($!{parameters.name}Temp.options.length > 0)
-        $!{parameters.name}Temp.options[0].selected = true
+        $!{parameters.name}Temp.options[0].selected = true;
 }
-//-->
-</script>
-
-#parse("/template/xhtml/controlfooter.vm")
+</script>

src/java/template/xhtml/combobox.vm

-#parse("/template/xhtml/controlheader.vm")
-#parse("/template/simple/combobox.vm")
-#parse("/template/xhtml/controlfooter.vm")
+#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/combobox.vm")#parse("/template/xhtml/controlfooter.vm")

src/java/template/xhtml/doubleselect.vm

-#parse( "/template/xhtml/controlheader.vm" )
-#parse( "/template/simple/doubleselect.vm" )
-#parse( "/template/xhtml/controlfooter.vm" )
+#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/doubleselect.vm")#parse("/template/xhtml/controlfooter.vm")

src/test/com/opensymphony/webwork/TestAction.java

     private List list2;
 
     //~ Methods ////////////////////////////////////////////////////////////////
-
-    public void setArray(String[] array) {
-        this.array = array;
-    }
-
-    public String[] getArray() {
-        return array;
+    public Collection getCollection() {
+        return collection;
     }
 
     public void setCollection(Collection collection) {
         this.collection = collection;
     }
 
-    public Collection getCollection() {
-        return collection;
+    public Map getMap() {
+        return map;
     }
 
-    public void setFoo(String foo) {
-        this.foo = foo;
+    public void setMap(Map map) {
+        this.map = map;
     }
 
     public String getFoo() {
         return foo;
     }
 
-    public void setList(String[][] list) {
-        this.list = list;
+    public void setFoo(String foo) {
+        this.foo = foo;
     }
 
-    public String[][] getList() {
-        return list;
+    public String getResult() {
+        return result;
     }
 
-    public List getList2() {
-        return list2;
+    public void setResult(String result) {
+        this.result = result;
     }
 
-    public void setList2(List list2) {
-        this.list2 = list2;
+    public User getUser() {
+        return user;
     }
 
-    public void setMap(Map map) {
-        this.map = map;
+    public void setUser(User user) {
+        this.user = user;
     }
 
-    public Map getMap() {
-        return map;
+    public String[] getArray() {
+        return array;
     }
 
-    public void setResult(String result) {
-        this.result = result;
+    public void setArray(String[] array) {
+        this.array = array;
     }
 
-    public String getResult() {
-        return result;
+    public String[][] getList() {
+        return list;
     }
 
-    public void setUser(User user) {
-        this.user = user;
+    public void setList(String[][] list) {
+        this.list = list;
     }
 
-    public User getUser() {
-        return user;
+    public List getList2() {
+        return list2;
+    }
+
+    public void setList2(List list2) {
+        this.list2 = list2;
     }
 
     public String execute() throws Exception {

src/test/com/opensymphony/webwork/views/jsp/ui/DoubleSelectTest.java

+package com.opensymphony.webwork.views.jsp.ui;
+
+import com.opensymphony.webwork.TestAction;
+import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:m.bogaert@memenco.com">Mathias Bogaert</a>
+ * @version $Revision$
+ */
+public class DoubleSelectTest extends AbstractUITagTest {
+
+    public void testDouble() throws Exception {
+        TestAction testAction = (TestAction) action;
+
+        Region antwerp = new Region("Antwerp", "AN");
+        Region gent = new Region("Gent", "GN");
+        Region brugge = new Region("Brugge", "BRG");
+        ArrayList belgiumRegions = new ArrayList();
+        belgiumRegions.add(antwerp);
+        belgiumRegions.add(gent);
+        belgiumRegions.add(brugge);
+        Country belgium = new Country("Belgium", "BE", belgiumRegions);
+
+        Region paris = new Region("Paris", "PA");
+        Region bordeaux = new Region("Bordeaux", "BOR");
+        ArrayList franceRegions = new ArrayList();
+        franceRegions.add(paris);
+        franceRegions.add(bordeaux);
+        Country france = new Country("France", "FR", franceRegions);
+
+        Collection collection = new ArrayList(2);
+        collection.add("AN");
+        testAction.setCollection(collection);
+
+        List countries = new ArrayList();
+        countries.add(belgium);
+        countries.add(france);
+
+        testAction.setList2(countries);
+
+        DoubleSelectTag tag = new DoubleSelectTag();
+        tag.setPageContext(pageContext);
+        tag.setLabel("'mylabel'");
+        tag.setName("'foo'");
+        tag.setDoubleName("'region'");
+
+        tag.setList("list2");
+        tag.setDoubleList("regions");
+
+        tag.setListKey("iso");
+        tag.setDoubleListKey("key");
+        tag.setListValue("name");
+        tag.setDoubleListValue("name");
+
+        tag.setFormName("'inputForm'");
+
+        tag.setOnmousedown("'window.status=\\'onmousedown\\';'");
+        tag.setOnmousemove("'window.status=\\'onmousemove\\';'");
+        tag.setOnmouseout("'window.status=\\'onmouseout\\';'");
+        tag.setOnmouseover("'window.status=\\'onmouseover\\';'");
+        tag.setOnmouseup("'window.status=\\'onmouseup\\';'");
+
+        int result = tag.doEndTag();
+
+        verify(SelectTag.class.getResource("DoubleSelect-1.html"));
+    }
+
+    public class Country {
+        String name;
+        String iso;
+        Collection regions;
+
+        public Country(String name, String iso, Collection regions) {
+            this.name = name;
+            this.iso = iso;
+            this.regions = regions;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getIso() {
+            return iso;
+        }
+
+        public Collection getRegions() {
+            return regions;
+        }
+    }
+
+    public class Region {
+        String name;
+        String key;
+
+        public Region(String name, String key) {
+            this.name = name;
+            this.key = key;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getKey() {
+            return key;
+        }
+    }
+}