Re: [OT] JSTL + Collection size
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. From: Robert Taylor [EMAIL PROTECTED] Reply-To: Struts Users Mailing List user@struts.apache.org To: Struts Users Mailing List user@struts.apache.org Subject: Re: [OT] JSTL + Collection size Date: Fri, 29 Apr 2005 07:30:49 -0400 Size: c:out value=${fn:length(my_collection}/ draegoon Z wrote: Just trying to find the ${my_collection.size} or ${my_collection.length}! Why is it not that simple? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [OT] JSTL + Collection size
It works now. Thanks to everyone for helpin. im looping through an array list of hashtables.. so my syntax goes like this.. it actually turned out to be easy cause i know the names of my key. Where my hashtable has keys named (firstname, lastname) c:forEach var=myCurrentHash items=${requestScope.ListOfThingsKey} c:out value=${myCurrentHash.firstname} / c:out value=${myCurrentHash.lastname} / /c:forEach -B -Original Message- From: draegoon Z [mailto:[EMAIL PROTECTED] Sent: Friday, April 29, 2005 2:22 PM To: user@struts.apache.org Subject: Re: [OT] JSTL + Collection size 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. From: Robert Taylor [EMAIL PROTECTED] Reply-To: Struts Users Mailing List user@struts.apache.org To: Struts Users Mailing List user@struts.apache.org Subject: Re: [OT] JSTL + Collection size Date: Fri, 29 Apr 2005 07:30:49 -0400 Size: c:out value=${fn:length(my_collection}/ draegoon Z wrote: Just trying to find the ${my_collection.size} or ${my_collection.length}! Why is it not that simple? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT] JSTL + Collection size
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]
RE: [OT] JSTL + Collection size
Sorry, I left out a paren. Try this: c:out value=${fn:length(my_collection)}/ Yes, you have to import the following: %@ taglib uri=http://jakarta.apache.org/taglibs/fmt; prefix=fmt % BTW, functions are part of JSTL1.1. /robert -Original Message- From: draegoon Z [mailto:[EMAIL PROTECTED] Sent: Friday, April 29, 2005 2:22 PM To: user@struts.apache.org Subject: Re: [OT] JSTL + Collection size 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. From: Robert Taylor [EMAIL PROTECTED] Reply-To: Struts Users Mailing List user@struts.apache.org To: Struts Users Mailing List user@struts.apache.org Subject: Re: [OT] JSTL + Collection size Date: Fri, 29 Apr 2005 07:30:49 -0400 Size: c:out value=${fn:length(my_collection}/ draegoon Z wrote: Just trying to find the ${my_collection.size} or ${my_collection.length}! Why is it not that simple? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT] JSTL + Collection size
handling orphaned columns in a dynamic check boxes tile: td %-- to handle orphaned columns: if last in collection, find how many short of full row. --% c:set var=scope tiles:getAsString name=collection_scope / /c:set c:choose c:when test=${scope == 'page'} c:set var=ck_options value=${pageScope[pageScope.collection_name]} / /c:when c:when test=${scope == 'request'} c:set var=ck_options value=${requestScope[pageScope.collection_name]} / /c:when c:when test=${scope == 'session'} c:set var=ck_options value=${sessionScope[pageScope.collection_name]} / /c:when c:when test=${scope == 'application'} c:set var=ck_options value=${applicationScope[pageScope.collection_name]} / /c:when c:otherwise c:out value=collection scope not defined properly in check_boxes widget! / /c:otherwise /c:choose c:set var=ck_options_size value=${ck_options.length} / c:if var=ck_options_size test=${(pageScope['index']+1)} c:set var=colspan value=${(pageScope['index']+1)%pageScope['per_row']} / c:out value=${colspan} / /c:if From: Wendy Smoak [EMAIL PROTECTED] Reply-To: Struts Users Mailing List user@struts.apache.org To: Struts Users Mailing List user@struts.apache.org Subject: Re: [OT] JSTL + Collection size Date: Thu, 28 Apr 2005 16:39:52 -0700 From: draegoon Z [EMAIL PROTECTED] Just trying to find the ${my_collection.size} or ${my_collection.length}! Why is it not that simple? Unfortunately, the Collection interface only has a 'size' method, not the 'getSize' that would be required for what you wrote to work. What are you trying to do? Maybe there's another way to get it done. IOW, why do you need the size? -- Wendy Smoak - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]