ServletException: Cannot create iterator for this collection

hi,

i am using struts action class with struts tags to display

data in jsp page.

in struts class i am return arraylist ,

same list i am displaing in jsp.

if Arraylist have data ,i am not getting error.

but if arraylist empty ,i am getting ServletException: Cannot create iterator for this collection

<logic:iterate id="result" name="fileList" >

<td><bean:write name="result" property="fileName"/></td>

</logic:iterate

can any one help how to avoid this exception?

thanks

siav>

[586 byte] By [sivasaia] at [2007-10-3 1:47:28]
# 1
Do you have a bean (of type ArrayList) called fileList in scope? Or is it so that fileList is a property(of type Collection) of a bean that is in scope? Can you post the bean class and the action form?ram.
Madathil_Prasada at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You could use <bean:size> to get the size of the list and conditionally execute the logic:iterate, something like this :

<bean:size id="id" name="collection" />

<logic:lessEqual value="0" name="id">

The length is zero

</logic:lessEqual>

<logic:greaterThan value="0" name="id">

//your logic:iterate here...

</logic:greaterThan>

ragh_dra at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> You could use <bean:size> to get the size of the list

> and conditionally execute the logic:iterate,

> something like this :

>

That will work, but not necessary. If the collection is empty, the iterate tag just skips - it doesnt throw an exception (tested)

The problem I guess is that the bean with the specified name is not a Collection. It may be a property of the bean that is a collection in which case the tag should have a property attribute.

ram.

Madathil_Prasada at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Agree. But, he says that the logic:iterate works when the collection is not empty. So, the bean must be a Collection if it works in one case..don't you think so?
ragh_dra at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
hi,thanks for your reply.solve my problem.siva
sivasaia at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

I got the error Pl help

javax.servlet.jsp.JspException: ServletException in '/home.jsp': Cannot create iterator for this collection

this is the code

<logic:iterate name="result" property="numtrue" id="true" ></logic:iterate>

<logic:iterate name="result" property="nlphavalue" id="alpha" >

<bean:write name="result" property="numvalue" scope="request" />

</logic:iterate>

Pl help me

Bhagya

Bmalitha at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I got the error Pl help

javax.servlet.jsp.JspException: ServletException in '/home.jsp': Cannot create iterator for this collection

this is the code

<logic:iterate name="result" property="numtrue" id="true" ></logic:iterate>

<logic:iterate name="result" property="nlphavalue" id="alpha" >

<bean:write name="result" property="numvalue" scope="request" />

</logic:iterate>

Pl help me

Bhagya

Bmalitha at 2007-7-14 18:45:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...