Commits

Anonymous committed c095961

select tag passes the tests

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

Comments (0)

Files changed (4)

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

  */
 package com.opensymphony.webwork.views.jsp.ui;
 
+import com.opensymphony.xwork.util.OgnlValueStack;
+
 
 /**
  * @version $Id$
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private String defaultKey = null;
-    private String defaultValue = null;
-    private boolean emptyOption;
-    private boolean multiple;
-    private int size;
+    protected String emptyOptionAttr;
+    protected String multipleAttr;
+    protected String sizeAttr;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void setDefaultKey(String defaultKey) {
-        this.defaultKey = defaultKey;
-    }
-
-    public String getDefaultKey() {
-        return defaultKey;
-    }
-
-    public void setDefaultValue(String defaultValue) {
-        this.defaultValue = defaultValue;
-    }
-
-    public String getDefaultValue() {
-        return defaultValue;
+    public void setEmptyOption(String emptyOption) {
+        this.emptyOptionAttr = emptyOption;
     }
 
-    public void setEmptyOption(boolean emptyOption) {
-        this.emptyOption = emptyOption;
+    public void setMultiple(String multiple) {
+        this.multipleAttr = multiple;
     }
 
-    public boolean isEmptyOption() {
-        return emptyOption;
+    public void setSize(String size) {
+        this.sizeAttr = size;
     }
 
-    public void setMultiple(boolean multiple) {
-        this.multiple = multiple;
-    }
+    public void evaluateExtraParams(OgnlValueStack stack) {
+        super.evaluateExtraParams(stack);
 
-    public boolean isMultiple() {
-        return multiple;
-    }
+        if (emptyOptionAttr != null) {
+            addParam("emptyOption", stack.findValue(emptyOptionAttr, String.class));
+        }
 
-    public void setSize(int size) {
-        this.size = size;
-    }
+        if (multipleAttr != null) {
+            addParam("defaultKey", stack.findValue(multipleAttr, String.class));
+        }
 
-    public int getSize() {
-        return size;
-    }
-
-    /**
-     * Clears all the instance variables to allow this instance to be reused.
-     */
-    public void release() {
-        super.release();
-        this.emptyOption = false;
-        this.multiple = false;
-        this.size = 0;
-        this.defaultKey = null;
-        this.defaultValue = null;
+        if (sizeAttr != null) {
+            addParam("size", stack.findValue(sizeAttr, String.class));
+        }
     }
 
     protected String getDefaultTemplate() {

src/java/templates/xhtml/select.vm

 #parse( "/templates/xhtml/controlheader.vm" )
-<select name="$!{tag.Name}" #if( $tag.Size > 0 )size="${tag.Size}" #end #if( $tag.Multiple ) multiple#end >
-#if($tag.defaultKey  || $tag.DefaultValue)
-  #set( $defaultKeyValue = $stack.findValue("getText('$!tag.defaultKey')") )
-  #if( !$defaultKeyValue)
-    #set( $defaultKeyValue = $!tag.defaultKey )
-  #end
-  <option value="$!{tag.defaultValue}"#if( $tag.contains($tag.ActualValue, $itemValue) ) selected="selected"#end>$!{defaultKeyValue}</option>
-#end
-#if( $tag.EmptyOption)<option></option>#end
-#set( $items = ${stack.findValue($tag.list)} )
+<select
+      #if ($parameters.name)      name="$parameters.name"     #end
+      #if ($parameters.size)      name="$parameters.size"     #end
+      #if ($parameters.multiple == "true")       multiple     #end
+>
+#if( $parameters.emptyOption == "true" )<option></option>#end
+#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
-  <option value="$!{itemValue}"#if( $tag.contains($tag.ActualValue, $itemValue) ) selected#end>$!{itemKey}</option>
-#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
+        <option
+            value="$!itemKey"
+            #if( $parameters.value && $itemKey && $parameters.value == $itemKey )selected#end
+        >$!itemValue</option>
 
+        #set ($trash = $stack.pop())
+    #end
 #else
   &nbsp;
 #end

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

   <td align="right" valign="top"><label class="label">mylabel:</label></td>
   <td>
 <select name="myname"   >
-          <option value="world">hello</option>
-          <option value="bar" selected>foo</option>
+          <option></option>
+          <option value="hello" >world</option>
+          <option value="foo" selected >bar</option>
 
 </select>
   </td>

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

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