While developing a struts application I found it extremely useful to be able to iterate over an array of primitives without sending the array through wrapper functions every time first. I developed a very localized, obvious, and short patch to IterateTag which allows this functionality. (below & attached). I'd welcome any comments/suggestions as to better ways to do this patch, and if appropriate, information from a maintainer on how to get it merged into the main struts source tree.
---
jakarta-struts-1.0.1-src/src/share/org/apache/struts/taglib/logic/IterateTag
.java Wed Jun 13 22:24:28 2001
+++
jakarta-struts-1.0.1-src-mfr/src/share/org/apache/struts/taglib/logic/Iterat
eTag.java Thu Jan 31 09:31:30 2002
@@ -310,9 +310,15 @@
// Construct an iterator for this collection
- if (collection.getClass().isArray())
- collection = Arrays.asList((Object[]) collection);
- if (collection instanceof Collection)
+ if (collection.getClass().isArray()) {
+ int length = java.lang.reflect.Array.getLength(collection);
+ Collection c = new ArrayList();
+ for(int i=0; i<length; i++) {
+ c.add(java.lang.reflect.Array.get(collection, i));
+ }
+ iterator = c.iterator();
+ }
+ else if (collection instanceof Collection)
iterator = ((Collection) collection).iterator();
else if (collection instanceof Iterator)
iterator = (Iterator) collection;
Thanks,
Marty
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Martin Rose
[EMAIL PROTECTED]
Interactive Developer
JGSullivan Interactive
320 W. Ohio Suite 3E
Chicago IL 60610
312-943-1600
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
primitiveIterate.diff
Description: Binary data
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
