File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl and size

 
Neeraj Vij
Ranch Hand
Posts: 315
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Muthya Prashant
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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" ><cut value="${themeDTO.theme}"/></a> <br>
</c:if>
</c:forEach>

Thanks,
Neeraj.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it worked for me
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic