draegoon Z wrote the following on 4/29/2005 2:21 PM:
I tried it, said the syntax is wrong.

I didn't see anything about "fn" in the JSTL spec.
Where can I find documentation on this?

Do I need to import a library?

For now, I am just using a c:for loop to count the collection, but
this can't be the cleanest way.

The fn tags will work if using JSP2.0. If you are using JSP2.0 (Tomcat 5) then the fn stuff will work as is from the standard.jar


http://jakarta.apache.org/taglibs/doc/standard-doc/GettingStarted.html

Acutally, if you aren't using the fn tags, I still wouldn't count it with a loop on the page.

Another option is that I'm assuming you know where you are putting the list into scope (ie wherever you are doing setAttribute("listName", list). Since you know that, just shove the size into scope there also. At one point I had a little utility method that not only put the collection into request scope but also added the size into scope. So if the list name was "dogs" it would put "dogs_size" into scope as well.

It was a static method in a Helper class...

public static void setCollectionInRequest(HttpServletRequest request, String attributeName, Collection collection) {
if ( collection != null ) {
request.setAttribute(attributeName + "_size", new Integer(collection.size()));
}
request.setAttribute(attributeName, collection);
}



So then instead of using request.setAttribute(...) in your Action or wherever, use...


UIhelper.setCollectionInRequest( request, "listName", yourList )

So with one line you get both your list and it's size put into scope.

--
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to