This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterate tag for Vector

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
Vector v = new Vector();
v.addElement("a");
v.addElement("a");
v.addElement("a");
%>

<logic:iterate id="v" name="it">
<bean:write name="it" property = "value" />
</logic:iterate>

I still do not understand what id is ? name is and property is

I keep getting out of scope error.

Please help.
 
Nimchi Yung
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set your collection in the scope.

e.g.

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks nImchi

<%
Vector v = (Vector) request.getAttribute("domainlist");
for (int i = 0; i < v.size(); i++) {
domain d = new domain();
d = (domain) v.elementAt(i);
%>
Display info in htm
<%}%>

Can you please relate this with iterate tag and explain to me .
Nimchi, I appreciate your help.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
id becomes the variable name for each iteration
<%Vector v = new Vector();
v.addElement("a");
v.addElement("b");
v.addElement("c");
pageContext.setAttribute("it", v);%>


<logic:iterate id="blabla" name="it">
<bean:write name="blabla" property = "value" />
</logic:iterate>
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off topic, and on soapbox: Vector and logic:iterate?!? It's 2004, List/ArrayList have been part of the JDK for yonks to replace the ill-conceived legacy collection classes, and the vastly superior JSTL has made the Struts logic tags instantly obsolete, what, two years ago or so? Why is anybody still using this?

- Peter
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can I use JSTL tags in a struts program ? if so I need some sample
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe logic:iterate is still being used because JSTL isn't all that vastly superior.

I can't disagree too much with your case on Vector, although it may have been worth giving a brief explanation of why to not use it other than to flame it for being old.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use JSTL tags in a "Struts Program." JSTL tags are like any tag library that you import. Struts does not prevent you from using any other tag library.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marc Peabody:
Maybe logic:iterate is still being used because JSTL isn't all that vastly superior.
Do you really think so? The Struts tags have no serious expression language support, have only a limited ability to plug into each other the way the JSTL tags can, and as far as iteration goes the LoopTagStatus object alone is already worth the price of admission (see the c:forEach varStatus attribute). And last but not least the Struts team encourages their users to choose the JSTL over the Struts tags. It seems to me that the Struts logic taglib has been dead ever since the JSTL became mainstream and it never ceases to surprise me how many people are still interested in the corpse

I can't disagree too much with your case on Vector, although it may have been worth giving a brief explanation of why to not use it other than to flame it for being old.
It wouldn't surprise me if my rants about the old-style collection classes numbered in the triple digits by now, so you'll have to forgive me if explaining it gets a bit old. Point taken, though: that is still no excuse for the guerilla sniper style of posting I employed above. My apologies.

Briefly, then.
  • There's been a feature-complete Collections Framework since Java developers went around in bear skins and carved their software in flint punchcards - since JDK 1.2, to be precise. Use it. The legacy classes ('cause that's what Sun calls them - read the collections doc in the SDK!) Vector, Hashtable and Enumeration are just needless intellectual baggage. Forget them until you have to program against a legacy API.
  • The legacy collections have been forcibly retrofitted with the Collections interfaces, which makes their API hopelessly inconsistent and confusing. What shall I use to iterate over my Vector today, an Iterator or an Enumeration? Give a Vector or Hashtable to different developers and they will use different methods. Unless they're smart enough to know that they should only program against the List (or Map) interface.
  • Vector and Hashtable are synchronized. Most of the time these objects are used in a single-threaded fashion and this is completely unnecessary overhead.
  • And when you do require multi-threaded access... the synchronization is in almost all cases totally useless and still completely unnecessary overhead. You see, most of the time it's not the little Vector methods that need to be atomic with respect to other threads, but the more coarse-grained business operations that you write using the Vector.
  • It gets worse. I have seen too many cases where inexperienced developers think their code is threadsafe because they use Vector (or Hashtable), and "Vector is threadsafe". They get lured into a false sense of security and I don't want to know how many subtle concurrency problems made it into production because of this.
  • If you happen to hit one of the rare cases where you need a synchronized collection, use the wrapper methods in Collections.
  • Do you seriously think Josh Bloch et al didn't know exactly what they were doing when they introduced ArrayList and HashMap into a JDK which already had Vector and Hashtable?
  • HTH

    - Peter
    [ August 23, 2004: Message edited by: Peter den Haan ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic