aspose file tools*
The moose likes JSP and the fly likes jstl and size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl and size" Watch "jstl and size" New topic
Author

jstl and size

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
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

Joined: Apr 19, 2005
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61412
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

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

Joined: Nov 25, 2003
Posts: 315
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

Joined: Jan 10, 2002
Posts: 61412
    
  67

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

Joined: Nov 25, 2003
Posts: 315
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

Joined: Jan 10, 2002
Posts: 61412
    
  67

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

Joined: Nov 25, 2003
Posts: 315
Hi,

Thanks for your prompt replies. You saved my night.

Thanks a lo for the help.

Neeraj.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
it worked for me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl and size