Win a copy of Spark in Action this week in the Open Source Projects 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Confusion with logic:iterate tag

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
i know, at least in this forum i will get the answer........
here is the very basic question,but unfortunately i am unable to find out the mistake
as per my knowledge we can iterate collection in 2 ways (may be more..).

1st one is like :

a) set the collection in request as attribute in Action class
b) get the same in jsp

java.util.ArrayList employeeList = (java.util.ArrayList)request.getAttribute("employeeList");

c) then iterate it in jsp
<logic:iterate collection="<%=employeeList%>" id="emp" type="com.risl.beans.Employee">
<tr>
<td><bean:write name="emp" property="empId"/></td>
...............
</tr>
</logic:iterate>

the second one is like
a) make one form-property as collection with getter-setter
b) populate it with data in Action Class
c) then iterate it in jsp

<logic:iterate collection="employeeList" id="emp" type="com.risl.beans.Employee">
<tr>
<td><bean:write name="emp" property="empId"/></td>
...............
</tr>
</logic:iterate>

the question (more like a confusion) is in my projects ,only the 1st one works well.
i have tries a lot for 2nd way......but it always throws exception as
"cannot create iterator for this collection".

Can any one help me out ?

[for info i am using netbeans 5.5.1 with struts1.2.9 and tomcat 5.5.17]
 
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the iterate tag documentation. You don't use the collection attribute to identify a bean and a getter/setter. You use name and property.
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,
i will check.
[ March 21, 2008: Message edited by: vijay saraf ]
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<logic:iterate collection="employeeList" id="emp" type="com.risl.beans.Employee">


Above need to be changed, it is wrong. If your collection is form variable you need to give like this

<logic:iterate id="var" name="formName" property="formProperty" type="">
<logic:iterate>

HTH
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot both of you.
its now working.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic