I just realized the Collection cleanup patch was applied against only one of the two files (it was not applied to the TableTag.java file). Do you wish me to re-send the patch for the second file through SF? I'm sending it in this email, anyway, if you want just to apply it.
Thanks a lot,
Zorzella
Matt Raible wrote:
Done. In the future, maybe we should try to use the patch manager from SF for these? I don't know - it's pretty easy to do them as an e-mail attachment. As soon as we get JIRA setup, I believe we can submit patches to bugs and such too.Matt-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Luiz-Otavio Zorzella
Sent: Wednesday, February 12, 2003 7:17 PM
To: Matt Raible; [EMAIL PROTECTED]
Subject: Re: FW: [displaytag-devel] VOTE: release 0.8.5 now
Matt,
no problem at all... I'm using the table tag libs in here, and they are great... I'm happy to help out make them better...
Can I get you interested in another patch? This is the beggining of a cleanup of the internal data structures used by the tags to store the collection of objects to iterate over.
The original code only works with Lists. With the patch, it will work with Collections, Iterators and Maps as well (though some functions, like group totals are not available to these, due to limitations on the structures themselves). I'm also working on adding support for ResultSets, but I need a little more time for that...
Though the patch is not trivial (i.e. more than 10 lines :^>), I'm using it here successfully. Furthermore, it pretty much only changes declarations from List to Object and class casts, so it should work without any doubt in whatever it was working before...
Cheers,
Zorzella
Matt Raible wrote:
be nestedDone - thanks for the syntax. Matt-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Luiz-Otavio Zorzella
Sent: Tuesday, February 11, 2003 7:14 PM
To: Matt Raible
Cc: [EMAIL PROTECTED]
Subject: Re: FW: [displaytag-devel] VOTE: release 0.8.5 now
I don't know about Tortoise CVS, though I can certainly send you the
patch in whichever format you like best. I successfully applied my own patch against a clean tree, like this:
$ cd cvs/displaytag
$ patch -p0 < ~/DISPLAYNESTEDPATCH.txt
patching file src/org/apache/taglibs/display/ColumnTag.java
Let me know...
Zorzella
Matt Raible wrote:
Anyone know how to apply this sucker? I tried to figure itout usingTortoiseCVS, but gave up after 5 minutes of banging my head against
the wall.
Thanks,
Matt
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of
Luiz-Otavio Zorzella
Sent: Tuesday, February 11, 2003 9:19 AM
To: John York
Cc: Kasper van Benten; [EMAIL PROTECTED]
Subject: Re: [displaytag-devel] VOTE: release 0.8.5 now
+1
I sent a trivial bugfix patch to allow column elements to
afterwards someinside other tags, but I have yet not gotten any feedback. I'd appreciate if this could be included in the release. Patch
included,again, as attachment. Zorzella John York wrote:+1 I'm assuming Ed has been using and tested this stuff. Itwouldn't begreat to release 'arbitrarily' and have problems with it from the
start. But I agree, we need to start somewhere and thissounds like agood thing to me. On Tue, 11 Feb 2003, Kasper van Benten wrote:+1 Let's roll a release! Gerhard Froehlich wrote:Hi,
I would like to generate the first voting.
"Let's release Ed's current 0.8.5 immediatly, do
Something 2 See!cleanup and release 0.9 quick to get started!" +1------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld =Something 2 See!http://www.vasoftware.com
_______________________________________________
displaytag-devel mailing list[EMAIL PROTECTED]https://lists.sourceforge.net/lists/listinfo/displaytag-devel
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something
2 See! http://www.vasoftware.com _______________________________________________
displaytag-devel mailing list [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld =
http://www.vasoftware.com _______________________________________________
displaytag-devel mailing list [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel
------------------------------------------------------- This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues. http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en _______________________________________________ displaytag-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/displaytag-devel
Index: src//org/apache/taglibs/display/TableTag.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag/src/org/apache/taglibs/display/TableTag.java,v
retrieving revision 1.2
diff -u -r1.2 TableTag.java
--- src//org/apache/taglibs/display/TableTag.java 6 Feb 2003 16:30:09 -0000
1.2
+++ src//org/apache/taglibs/display/TableTag.java 20 Feb 2003 21:11:25 -0000
@@ -15,13 +15,17 @@
package org.apache.taglibs.display;
import java.lang.reflect.InvocationTargetException;
+import java.sql.ResultSet;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.net.URL;
@@ -33,6 +37,15 @@
import javax.servlet.jsp.PageContext;
import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.beanutils.RowSetDynaClass;
+
+/* This would allow certain kinds of stuctures to be used (rather than
+ * java.util.Collections), but I did not want to introduce a dependency
+ * on struts for compilation...
+ *
+ * import org.apache.struts.util.*;
+ *
+ */
/**
* This tag takes a list of objects and creates a table to display those
@@ -158,8 +171,6 @@
private int pageNumber = 1;
private int exportType = EXPORT_TYPE_NONE;
- private List completeList = null;
-
// -------------------------------------------------------- Accessor methods
public void setList( Object v )
@@ -733,6 +744,30 @@
return returnValue;
}
+ /** Given an Object, let's do our best to iterate over it
+ */
+ public static Iterator getIterator (Object o) throws JspException {
+
+ Iterator iterator = null;
+
+ if( o instanceof Collection ) {
+ iterator = ( (Collection)o ).iterator();
+ } else if( o instanceof Iterator ) {
+ iterator = (Iterator)o;
+ } else if( o instanceof Map ) {
+ iterator = ( (Map)o ).entrySet().iterator();
+ /*
+ * This depends on importing struts.util.* -- see remarks in the import
+section of the file
+ *
+ * } else if( o instanceof Enumeration ) {
+ * iterator = new IteratorAdapter( (Enumeration)o );
+ * }
+ */
+ } else {
+ throw new JspException( "I do not know how to iterate over '" +
+o.getClass() + "'.");
+ }
+ return iterator;
+ }
/**
* This returns a list of all of the data that will be displayed on the
@@ -773,39 +808,27 @@
// are using
- Iterator iterator = null;
-
- // Todo - these needs cleaned up, we only show lists....
-
+ /* YIKES! If we use a RowSetDynaClass to wrap a ResultSet, we'd
+ * copy the entire set to a List -- not good at all if paging
+ * (though functional -- I tested). Furthermore, RowSetDynaClass
+ * is not yet officially released, so I'm leaving this out for
+ * now.
+ *
+ * Anyway, the proper semantics would involve a class like ResultSetDynaClass,
+ * but with some changes to the Iterator I'l trying to work on.
+ *
+ * if (collection instanceof ResultSet)
+ * try {
+ * collection = new RowSetDynaClass((ResultSet)collection).getRows ();
+ * } catch (java.sql.SQLException e) {
+ * throw new JspException( "Problems iterating over ResultSet.", e);
+ * }
+ */
+
if( collection.getClass().isArray() )
collection = Arrays.asList( (Object[])collection );
- if( collection instanceof List ) {
- collection = (List)collection;
- } else {
- Object[] objs = {collection};
- String msg =
- MessageFormat.format( prop.getProperty( "error.msg.invalid_bean" ), objs
);
-
- throw new JspException( msg );
- }
-
- // TODO - Deal with RowSets, ResultSets, Maps, Enumerations, etc...
-
- /*
- iterator = ( (Collection)collection ).iterator();
- } else if( collection instanceof Iterator ) {
- iterator = (Iterator)collection;
- } else if( collection instanceof Map ) {
- iterator = ( (Map)collection ).entrySet().iterator();
- } else if( collection instanceof Enumeration ) {
- iterator = new IteratorAdapter( (Enumeration)collection );
- } else {
- throw new JspException( "Could not figure out how to iterator over " +
- "the stuff that you gave me..." );
- }
- */
-
+ Iterator iterator = getIterator (collection);
// If the user has changed the way our default behavior works, then we
// need to look for it now, and resort things if needed before we ask
@@ -814,11 +837,11 @@
// Load our table decorator if it is requested
this.dec = this.loadDecorator();
- if( this.dec != null ) this.dec.init( this.pageContext, (List)collection );
+ if( this.dec != null ) this.dec.init( this.pageContext, collection );
if( !prop.getProperty( "sort.behavior" ).equals( "page" ) ) {
// Sort the total list...
- this.sortDataIfNeeded( (List)collection );
+ this.sortDataIfNeeded(collection );
// If they have changed the default sorting behavior of the table
@@ -832,9 +855,6 @@
}
}
- this.completeList = (List)collection;
- iterator = ( (List)collection ).listIterator();
-
// If they have asked for an subset of the list via the offset or length
// attributes, then only fetch those items out of the master list.
@@ -860,6 +880,8 @@
int pagesizeValue = this.getPagesizeValue();
if( pagesizeValue > 0 ) {
+ if (! (collection instanceof List) )
+ throw new JspException( "Paging is not available for collections of type
+'" + collection.getClass() + "'.");
helper = new SmartListHelper( (List)collection, pagesizeValue, this.prop );
// tlaw 12-10-2001
// added the if/else statement below to allow sending an empty list to
@@ -889,8 +911,11 @@
* based on the user clicking on the column headers.
*/
- private void sortDataIfNeeded( List viewableData )
+ private void sortDataIfNeeded( Object viewableData )
{
+ if (! (viewableData instanceof List))
+ throw new RuntimeException ("This function is only supported if the given
+collection is a java.util.List.");
+
// At this point we have all the objects that are supposed to be shown
// sitting in our internal list ready to be shown, so if they have clicked
@@ -911,7 +936,7 @@
}
if( this.sortOrder == SORT_ORDER_DECENDING ) {
- Collections.reverse( viewableData );
+ Collections.reverse( (List)viewableData );
}
}
}
@@ -934,7 +959,7 @@
String columnDecorator = ( (ColumnTag)columns.get( c ) ).getDecorator();
colDecorators[c] = loadColumnDecorator( columnDecorator );
if( colDecorators[c] != null )
- colDecorators[c].init( this.pageContext, this.completeList );
+ colDecorators[c].init( this.pageContext, this.list );
}
// Ok, start bouncing through our list.........
@@ -1191,7 +1216,7 @@
}
/**
- * This returns a table of data in CVS format
+ * This returns a table of data in CSV format
*/
private StringBuffer getRawData( List viewableData ) throws JspException
@@ -1204,7 +1229,7 @@
boolean decorated = prop.getProperty( "export.decorated" ).equals( "true" );
if( prop.getProperty( "export.amount" ).equals( "list" ) ) {
- iterator = this.completeList.iterator();
+ iterator = getIterator (this.list);
}
// If they want the first line to be the column titles, then spit them out
@@ -1289,7 +1314,7 @@
boolean decorated = prop.getProperty( "export.decorated" ).equals( "true" );
if( prop.getProperty( "export.amount" ).equals( "list" ) ) {
- iterator = this.completeList.iterator();
+ iterator = getIterator (this.list);
}
// If they want the first line to be the column titles, then spit them out
@@ -1378,7 +1403,7 @@
boolean decorated = prop.getProperty( "export.decorated" ).equals( "true" );
if( prop.getProperty( "export.amount" ).equals( "list" ) ) {
- iterator = this.completeList.iterator();
+ iterator = getIterator (this.list);
}
buf.append( "<table>\n" );
