• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Getting the List size in JSP

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to get the size of the list in jsp. I need the total size of the list to be displayed in the page. I couldn't yet find ot a solution for this. Is it possible at jsp to get the list size using jstl? or shall i use <% %> to get the size like jsp 1.0?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this a List interface ? It does not follow the javabeans convention, so I don't think that you can get the size of the list. A quick way would be to use a scriptlet <%= mylist.size() %>

If you want to avoid sciptlets, a little wrapper around your list, with a getSize() method could do the trick.
Or you could even put the list size in a request atribute.

If you're looping through the list before displaying the total number of records using itertors like c:forEach, you could keep the total count in a page-scoped variable.
[ April 11, 2006: Message edited by: Satou kurinosuke ]
 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply.

I'm searching a jstl implementation for my jsp code. I'm trying for a jstl and jsp 2.0 implementation for the following code

code

for(int i=offset.intValue(), l = Math.min(i + maxPageItems,arrResult.size()); i < l ;i++) {
MyBean result = (MyBean)arrResult.get(i);
<td><%=result.getCity()%></td>
............................................

if that for loop is omitted, then rest is working fine for me..

<c:forEach items="${searchResults}" var="searchResult" varStatus="searchIndex"> .....

while using the Math.min in the <c ut> its throwing an exception like this

/WEB-INF/pages/Search.jsp(329,14) The function min must be used with a prefix when a default namespace is not specified

How i can convert the above code to jstl and jsp 2.0? and is it possible to assign a scriplet as the value in a jstl tag?
 
Sheriff
Posts: 67641
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
${fn:length(list)}

You should have a copy of the JSTL Spec on your desk.
[ April 11, 2006: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This assumes that the values "offset" and "maxPageItems" are available to JSTL, and are not just scriptlet variables.
The call to Math.min has been replaced with a <c:if>

 
Elizabath Lima
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Stefan Evans

You have done a great work for me.

And everything working fine for me except calling a jsp from another jsp in the spring framework.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic