Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

jstl and size

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

How can i get the size of the list using and jstl and typecast it at the sametime to a userobject while traversing the list.

Thanks,
Neeraj
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using JSTL, you can iterate thru the list Object and if you are sure that the objects in the list contain some values then you can directly refer to the properties of those objects using ${listName.property}.

This also depends on various other factors like in which scope your list is stored in on your JSP.

Did i answer your question?

-Prashanth
SCJP.
 
Sheriff
Posts: 67637
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
If you are using a JSP 2.0 container and JSTL 1.1, the length function is available to obtain the size of any collection or the length of a string.

For example:

${fn:length(myList)}
[ June 16, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67637
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

Originally posted by Neeraj Vij:

How can i get the size of the list using and jstl and typecast it at the sametime to a userobject while traversing the list.



You want to cast a numeric value to a userobject? That makes no sense.

Or, did you really mean to cast the elements of the list?

If so, then there is no need for casting when using the JSTL and EL. An object is what an object is, and you can access its properties without any need for casting.
[ June 16, 2006: Message edited by: Bear Bibeault ]
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your inputs. I wanted to typecast the elements. Sorry for not being able to put it across properly.

I need to execute this code till themesList.size<2. I need inputs for it.

<c:forEach var="themeDTO" items="${themesList}">
<c:if test="${not empty themeDTO}">
<a href="#" class="anchor_button_placeholder" ><c:out value="${themeDTO.theme}"/></a> <br>
</c:if>
</c:forEach>

Thanks,
Neeraj.
 
Bear Bibeault
Sheriff
Posts: 67637
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

Originally posted by Neeraj Vij:

I need to execute this code till themesList.size<2. I need inputs for it.



I don't know what you mean by this. The size of the list doesn't change as you iterate through it, so how can you test for the size being less than 2?

Also, please be sure to enclose any posted code in UBB code tags to preserve the formatting.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I meant to say, when the count for the list reaches 2, I need to break out of the loop.

Thanks,
Neeraj.
 
Bear Bibeault
Sheriff
Posts: 67637
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
There is no "break" ability in the JSTL. What you'll need to do is set up a <c:if> inside the loop that only executes its contents when you need to.

For example:



Or, you could investigate the use of the begin and end attributes of the forEach tag.
[ June 16, 2006: Message edited by: Bear Bibeault ]
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your prompt replies. You saved my night.

Thanks a lo for the help.

Neeraj.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it worked for me
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic