Commits

plightbo  committed 8c2f7d2

only four tests failing now

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

  • Participants
  • Parent commits 78cb07f

Comments (0)

Files changed (10)

File src/java/com/opensymphony/webwork/views/jsp/IteratorTag.java

 import com.opensymphony.webwork.dispatcher.SessionMap;
 import com.opensymphony.webwork.dispatcher.ApplicationMap;
 import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.webwork.util.MakeIterator;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.BodyTagSupport;
             req.setAttribute("webwork.valueStack", stack);
         }
 
-
-        iterator = getIterator();
+        iterator = MakeIterator.convert(stack.findValue(value));
 
         // get the first
         if ((iterator != null) && iterator.hasNext()) {
         this.value = null;
     }
 
-    private Iterator getIterator() {
-        if (stack == null) {
-            return null;
-        }
-
-        Object o = stack.findValue(value);
-
-        if (o == null) {
-            return null;
-        }
-
-        if (o instanceof Collection) {
-            return ((Collection) o).iterator();
-        } else if (o.getClass().isArray()) {
-            return Arrays.asList((Object[]) o).iterator();
-        } else if (o instanceof Map) {
-            return ((Map) o).entrySet().iterator();
-        } else if (o instanceof Iterator) {
-            return (Iterator) o;
-        } else if (o instanceof Enumeration) {
-            return new EnumeratorIterator((Enumeration) o);
-        }
-
-        return null;
-    }
-
 }

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

  */
 package com.opensymphony.webwork.views.jsp.ui;
 
+import com.opensymphony.xwork.util.OgnlValueStack;
+import com.opensymphony.webwork.util.MakeIterator;
+
 import java.lang.reflect.Array;
 
 import java.util.Collection;
 public abstract class AbstractListTag extends AbstractUITag {
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private Object listValue;
-    private String list;
-    private String listKey;
+    protected String listAttr;
+    protected String listKeyAttr;
+    protected String listValueAttr;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void setList(String list) {
-        this.list = list;
-    }
-
-    public String getList() {
-        return list;
+        this.listAttr = list;
     }
 
     public void setListKey(String listKey) {
-        this.listKey = listKey;
-    }
-
-    public String getListKey() {
-        return listKey;
-    }
-
-    public void setListValue(Object listValue) {
-        this.listValue = listValue;
+        this.listKeyAttr = listKey;
     }
 
-    public Object getListValue() {
-        return listValue;
+    public void setListValue(String listValue) {
+        this.listValueAttr = listValue;
     }
 
     public boolean contains(Object obj1, Object obj2) {
         return false;
     }
 
-    /**
-     * Clears all the instance variables to allow this instance to be reused.
-     */
-    public void release() {
-        super.release();
-        this.list = null;
-        this.listKey = null;
-        this.listValue = null;
+    void evaluateParams(OgnlValueStack stack) {
+        if (listAttr != null) {
+            addParam("list", MakeIterator.convert(stack.findValue(listAttr)));
+        }
+
+        if (listKeyAttr != null) {
+            addParam("listKey", listKeyAttr);
+        }
+
+        if (listValueAttr != null) {
+            addParam("listValue", listValueAttr);
+        }
     }
+
 }

File src/java/templates/xhtml/radio.vm

 #parse( "/templates/xhtml/controlheader.vm" )
-#set( $items = ${stack.findValue($tag.list)} )
+#set( $items = $parameters.list )
 #if( $items )
-#foreach( $item in $items )
-  #if( $tag.ListKey )
-      #set( $itemKey = $ognl.findValue($tag.ListKey, $item) )
-  #else
-      #set( $itemKey = $item.toString() )
-  #end
-  #if( $tag.ListValue )
-      #set( $itemValue = $ognl.findValue($tag.ListValue, $item) )
-  #else
-      #set( $itemValue = $item.toString() )
-  #end
-<label class="label" for="${tag.Name}$!{itemValue}">$!{itemKey}</label> <input type="radio" name="${tag.Name}" value="$!{itemValue}" #if( $tag.ActualValue && $itemValue && $tag.ActualValue == $itemValue )checked="checked"#end/>
-#end
+    #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
+
+        <label class="label" for="$!parameters.name$!itemKey">$!itemValue</label>
+        <input
+            type="radio"
+            #if ($parameters.name)      name="$parameters.name"     #end
+            #if ($itemKey)              value="$itemKey"            #end
+            #if( $parameters.value && $itemKey && $parameters.value == $itemKey )checked="checked"#end/>
 
+        #set ($trash = $stack.pop())
+    #end
 #else
   &nbsp;
 #end

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

     private String result;
     private String[] array;
     private String[][] list;
+    private Map map;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         return list;
     }
 
+    public void setMap(Map map) {
+        this.map = map;
+    }
+
+    public Map getMap() {
+        return map;
+    }
+
     public void setResult(String result) {
         this.result = result;
     }

File src/test/com/opensymphony/webwork/views/jsp/ui/CheckboxTest.java

     public CheckboxTest() {
     }
 
-    public CheckboxTest(String s) {
-        super(s);
-    }
-
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void testChecked() throws Exception {

File src/test/com/opensymphony/webwork/views/jsp/ui/Radio-1.txt

 <tr>
-  <td align="right" valign="top"><label class="label">{mylabel}:</label></td>
+  <td align="right" valign="top"><label class="label">mylabel:</label></td>
   <td>
-        <label class="label" for="mynameworld">hello</label> <input type="radio" name="myname" value="world" />
-        <label class="label" for="mynamebar">foo</label> <input type="radio" name="myname" value="bar" />
+        <label class="label" for="mynamehello">world</label> <input type="radio" name="myname" value="hello" />
+        <label class="label" for="mynamefoo">bar</label> <input type="radio" name="myname" value="foo" />
 
   </td>
 </tr>

File src/test/com/opensymphony/webwork/views/jsp/ui/RadioTest.java

 import org.apache.velocity.Template;
 import org.apache.velocity.app.Velocity;
 
+import java.util.HashMap;
+
 
 /**
  * @version $Id$
 
         RadioTag tag = new RadioTag();
         tag.setPageContext(pageContext);
-        tag.setLabel("mylabel");
-        tag.setName("myname");
-        tag.setValue("peek().list[1][1]");
+        tag.setLabel("'mylabel'");
+        tag.setName("'myname'");
+        tag.setValue("");
         tag.setList("list");
-        tag.setListKey("[0]");
-        tag.setListValue("[1]");
+        tag.setListKey("that[0]");
+        tag.setListValue("that[1]");
 
         int result = tag.doEndTag();
 
         verify(RadioTag.class.getResource("Radio-1.txt"));
     }
+
+    public void testMapChecked() throws Exception {
+        Template template = Velocity.getTemplate(AbstractUITag.THEME + RadioTag.TEMPLATE);
+        Assert.assertNotNull(template); // ensure this is a valid decorators
+
+        TestAction testAction = (TestAction) action;
+        testAction.setFoo("bar");
+        HashMap map = new HashMap();
+        map.put("1", "One");
+        map.put("2", "Two");
+        testAction.setMap(map);
+
+        RadioTag tag = new RadioTag();
+        tag.setPageContext(pageContext);
+        tag.setLabel("'mylabel'");
+        tag.setName("'myname'");
+        tag.setValue("1");
+        tag.setList("map");
+        tag.setListKey("key");
+        tag.setListValue("value");
+
+        int result = tag.doEndTag();
+
+        verify(RadioTag.class.getResource("Radio-2.txt"));
+    }
 }

File src/test/com/opensymphony/webwork/views/jsp/ui/Select-1.txt

 <tr>
-  <td align="right" valign="top"><label class="label">{mylabel}:</label></td>
+  <td align="right" valign="top"><label class="label">mylabel:</label></td>
   <td>
 <select name="myname"   >
           <option value="world">hello</option>

File src/test/com/opensymphony/webwork/views/jsp/ui/SelectTest.java

         SelectTag tag = new SelectTag();
         tag.setPageContext(pageContext);
         tag.setEmptyOption(false);
-        tag.setLabel("mylabel");
-        tag.setName("myname");
-        tag.setValue("that.list[1][1]");
+        tag.setLabel("'mylabel'");
+        tag.setName("'myname'");
+        tag.setValue("'bar'");
         tag.setList("list");
-        tag.setListKey("[0]");
-        tag.setListValue("[1]");
+        tag.setListKey("that[0]");
+        tag.setListValue("that[1]");
 
         int result = tag.doEndTag();
 

File src/test/com/opensymphony/webwork/views/velocity/TagDirectiveTest.java

 import com.opensymphony.webwork.views.jsp.WebWorkMockServletContext;
 import com.opensymphony.webwork.views.velocity.ui.MockTag;
 import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.config.ConfigurationManager;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import junit.framework.Assert;
 import junit.framework.TestCase;
     protected void setUp() throws Exception {
         super.setUp();
 
+        ConfigurationManager.destroyConfiguration();
+
         OgnlValueStack stack = new OgnlValueStack();
         ActionContext.setContext(new ActionContext(stack.getContext()));