Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Linda Xu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic