File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to use the taglib to loop through only part of the collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to use the taglib to loop through only part of the collection" Watch "How to use the taglib to loop through only part of the collection" New topic
Author

How to use the taglib to loop through only part of the collection

Linda Xu
Ranch Hand

Joined: Feb 14, 2000
Posts: 51
Hi, All
I am trying to use the taglib custom action to replace the java code in my JSP files.
For example, originally I have:
<%
Vector myVec;
...
for(int i=0; i<myVec.size(); i++)
{ myObj = myVec.elementAt(i);
%>
<%= myObj.toString() %>
<%
}
%>
in my JSP file, now I can easily replace it by:
<ora:loop name="myVec" id="myObj" class="java.lang.String">
the obj is <%= myObj %>
</ora:loop>
The JSP using taglib will be easier to write and maintain than using embedded java code.
But, here I have a side effect: When use embedded java code, I have more control on the positions to loop through, e.g. I want to loop from the third element at the left until the third element at the right side of the vector, I can easily change the java code to:
...
for(int i=3; i< myVec.size()-2; i++)
...
But how to achieve this using the taglib custom action?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I haven't actually tried this, but it is a final (not beta) release, so it should work: the iterate tag from the Jakarta-Struts Project, http://jakarta.apache.org/struts/struts-logic.html#iterate . You can set the offset attribute to your starting vector index and the length attribute to the number of vector entries you want to process.

------------------
Miftah Khan
- Sun Certified Programmer for the Java 2 Platform
- Sun Certified Web Component Developer for the J2EE Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use the taglib to loop through only part of the collection