Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

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 %>
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?
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, . 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
look! it's a bird! it's a plane! It's .... a teeny tiny ad
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic