[cvs] expresso commit by lhamel: add convenience method for getting display

JCorporate Ltd jcorp at jcorp2.servlets.net
Wed Oct 20 00:42:44 PDT 2004


Log Message:
-----------
add convenience method for getting display string from currently selected validValue

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller:
        Input.java

Revision Data
-------------
Index: Input.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/Input.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/Input.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/Input.java -u -r1.27 -r1.28
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/Input.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/Input.java
@@ -78,6 +78,7 @@
 
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
@@ -724,4 +725,26 @@
         return multiple;
     } /* getMultiple() */
 
+    /**
+     * get the display string associated with the currently-selected (default).
+     * useful for a JSTL reuse of Input for output purposes, when
+     * the default value is an ID, while its partner ValidValue pairing is the display string.
+     * @return the display string associated with the currently-selected (default) value, or empty string if none found--never null
+     */
+    public String getSelectedDisplay() {
+        String result = "";
+        String currentIndex = getDefaultValue();
+        if ( currentIndex != null && validValues != null ) {
+            for (Iterator iterator = validValues.iterator(); iterator.hasNext();) {
+                ValidValue vv = (ValidValue) iterator.next();
+                if ( currentIndex.equals(vv.getValue())) {
+                    result = vv.getDescription();
+                    break;
+                }
+            }
+        }
+
+        if (result == null) result = "";
+        return result;
+    }
 } /* Input */


More information about the cvs mailing list