Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

accessing size of an arraylist using tag

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an arraylist called "searchResults" in my jsp. I can write

<% if(searchResults.size() > 0) { %>
...do my html work
<% } %>

what would be an equivalent scriptless code. I can use either struts or jsp tags.
Thanks
Imad
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i found it. its this

<c:if test="${listSize > 0}">

and include

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
Sheriff
Posts: 67592
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
That assumes that listSize has been set up a scoped variable prior to the JSP gaining control and is not a general solution.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The general solution that works in JSTL1.0 and JSTL1.1 would be using the keyword "empty"



JSTL1.1 introduced User functions, which fixed one of the major issues with JSTL - getting the length of a list.
If you have JSP2.0 / JSTL1.1, the length of a list can be found with the length function.
eg: ${fn:length(searchResults)}"
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies. For some reason EL doesn't seem to be working. when I write <c:if test="${not empty searchResults}">....my code</c:if> ...code never goes inside. and when I added the following code outside <c:if.../> it printed in the screen as it is. that is

${searchResults.size} and also ${fn:length(searchResults} ..to use fn i did inculde the following line in my jsp

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

I am using jstl 1.1 and tomcat 5.5
Thanks
 
Bear Bibeault
Sheriff
Posts: 67592
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
Is your web.xml set up properly as outlined in the JSP FAQ?
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Thats probably the reason why its not working. but when i tried declaring it the way in FAQ it gave me a red mark in web.xml and a very long message which wont go away even if i change it back to how it is right now. is it a known problem?
 
Bear Bibeault
Sheriff
Posts: 67592
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
No, there should be no problem if you specify the web.xml correctly.

What do you mnean by a "red mark"? In an IDE? If so, who cares... does it work when you deploy the application?
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Bear. You are right if there is a red mark in IDE who cares and yes the red mark was in the ide. I was just afraid if it will going to show on everyone elses machine when i check back in the web.xml but I hope it dont. anyways its working fine.

Thanks a lot.
 
Yeah, but is it art? What do you think tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic