Mercer
Mercer

Reputation: 9986

Error of iterator in mys JSP

TITLLE [...]

<logic:iterate id="listClient" name="Client">
 <table>
  <tr>
   <td>
    [...]
   </td>
  </tr>
 </table>
</logic:iterate>

But i have this error for my second iterate

javax.servlet.jsp.JspException: Cannot create iterator for this collection

Upvotes: 1

Views: 6264

Answers (3)

user2610247
user2610247

Reputation: 1

use this type of iterater to solve this problem.............

<tr>
    <td><b>RECD from :</b>&nbsp;&nbsp;&nbsp;&nbsp;
        <select name="vo.cuttingRecivedFrom" >
            <option value="">select</option>
            <logic:notEmpty name="storeList">
                <logic:iterate name="storeList" id="storeList1" indexId="count">
                    <option value="<bean:write name="storeList1" property="storeName"/>"><bean:write name="storeList1" property="storeName"/></option>
                </logic:iterate>
            </logic:notEmpty>
        </select>
    </td>
    <td><b>RECD in :</b>&nbsp;&nbsp;&nbsp;&nbsp;
        <select name="vo.cuttingRecivedFrom" >
            <option value="">select</option>
            <logic:notEmpty name="storeList">
                <logic:iterate name="storeList" id="storeList1" indexId="count1">
                    <option value="<bean:write name="storeList1" property="storeName"/>"><bean:write name="storeList1" property="storeName"/></option>
                </logic:iterate>
            </logic:notEmpty>
        </select>
    </td>
</tr> 

Upvotes: 0

user159088
user159088

Reputation:

The Cannot create iterator for this collection message is thrown by the iterate tag when it is not able to create an iterator for the collection you are passing to it.

The tag extracts an object from scope using the specified name, in this case Client and starts to check what type it is:

  • array of objects or primitives;
  • java.util.Collection;
  • java.util.Iterator;
  • java.util.Map;
  • java.util.Enumeration.

If it finds one of this object types it extracts the iterator in the appropriate way. If none of the above are a match you get javax.servlet.jsp.JspException: Cannot create iterator for this collection.

At this point I agree with Adeel Ansari's comment: "it doesn't make any sense to me when you are able to iterate once, but not again".

Are you doing something to the Client bean between the two iterator tags (i.e. is the presented code continuous in regards of the iterator tags)? Maybe you overwrite it with something that ain't a collection?

Upvotes: 4

mohdajami
mohdajami

Reputation: 9690

You are using the same id, change the id of the second one

Upvotes: 1

Related Questions