Struts tag <logic:iterate>

Discussion in 'Java' started by Jack_A, May 18, 2004.

  1. Jack_A

    Jack_A Guest

    Hello!
    I have a problem with struts tag <logic:iterate>

    There is a bean TestBean.java contains array of some class (e.g. B)
    and class B also contains array of some class (e.g. C)

    public class B{
    private C[] arrayC;
    public B(int n){
    arrayC = new C[n];
    int j;
    for(j = 0;j<n; j++){
    arrayC[j] = new C();
    }
    }
    public C[] getArrayC() { return arrayC;}
    public C getArrayC(int index) { return arrayC[index];}
    }

    public class TestBean {
    private B[] arrayB;
    public TestBean(int n){
    arrayB = new B[n];
    int j;
    for(j = 0;j<n; j++){
    arrayB[j] = new B(n);
    }
    }
    public B[] getArrayB() { return arrayB;}
    public B getArrayB(int index) { return arrayB[index];}
    }

    There is some code of jsp page:

    <%TestBean testBean = new TestBean(5);
    session.setAttribute("testBean", testBean);
    %>
    <table>
    <logic:iterate id="test" name="testBean" property="arrayB"
    indexId="i"
    scope="session">
    <tr>
    <td align="right"><html:text name='test'
    property="array"/>
    <logic:iterate id="test2" name="test"
    property="arrayC" indexId="j">
    <td align="right"><html:text name='test2'
    property="fielsOfClassC"/>
    </logic:iterate>
    <tr />
    </logic:iterate>
    </table>

    I try to iterate each element of arrayC, which is element of arrayB
    (which I try to iterate too) :).
    But "[ServletException in:/testApp/test.jsp] Cannot create iterator
    for this collection'"

    Sorry if I wasn't very clear.

    Can anyone give me some advice?
    Jack_A, May 18, 2004
    #1
    1. Advertising

  2. Jack_A

    Martin Guest

    (Jack_A) wrote in message news:<>...
    > Hello!
    > I have a problem with struts tag <logic:iterate>
    >
    > There is a bean TestBean.java contains array of some class (e.g. B)
    > and class B also contains array of some class (e.g. C)
    >
    > public class B{
    > private C[] arrayC;
    > public B(int n){
    > arrayC = new C[n];
    > int j;
    > for(j = 0;j<n; j++){
    > arrayC[j] = new C();
    > }
    > }
    > public C[] getArrayC() { return arrayC;}
    > public C getArrayC(int index) { return arrayC[index];}
    > }
    >
    > public class TestBean {
    > private B[] arrayB;
    > public TestBean(int n){
    > arrayB = new B[n];
    > int j;
    > for(j = 0;j<n; j++){
    > arrayB[j] = new B(n);
    > }
    > }
    > public B[] getArrayB() { return arrayB;}
    > public B getArrayB(int index) { return arrayB[index];}
    > }
    >
    > There is some code of jsp page:
    >
    > <%TestBean testBean = new TestBean(5);
    > session.setAttribute("testBean", testBean);
    > %>
    > <table>
    > <logic:iterate id="test" name="testBean" property="arrayB"
    > indexId="i"
    > scope="session">
    > <tr>
    > <td align="right"><html:text name='test'
    > property="array"/>
    > <logic:iterate id="test2" name="test"
    > property="arrayC" indexId="j">
    > <td align="right"><html:text name='test2'
    > property="fielsOfClassC"/>
    > </logic:iterate>
    > <tr />
    > </logic:iterate>
    > </table>
    >
    > I try to iterate each element of arrayC, which is element of arrayB
    > (which I try to iterate too) :).
    > But "[ServletException in:/testApp/test.jsp] Cannot create iterator
    > for this collection'"
    >
    > Sorry if I wasn't very clear.
    >
    > Can anyone give me some advice?


    I quickly simulated your example, and I didn't get this "cannot create
    iterator..."-message. First, I received other errors: I had to import
    the B- and C-class, then I got "no getter method...". So I specified
    the property-type to iterate over:

    <logic:iterate id="test" name="testBean" property="arrayB"
    scope="request" type="B">
    <tr>
    <td>Row...</td>
    <logic:iterate id="test2" name="test" property="arrayC" type="C">
    <td align="right"><bean:write name="test2"
    property="ceProperty"/>
    </logic:iterate>
    <tr />
    </logic:iterate>

    That's it. I had a simple String-variable "hello" with a getter-method
    in C, and voila: a 5x5-matrix filled with hellos.

    Try this. If it doesn't work, then post some more details (code of
    class C, J2EE-environment, etc).

    Good luck!
    Martin
    Martin, May 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gogo
    Replies:
    1
    Views:
    2,083
    Sudsy
    Sep 4, 2003
  2. Replies:
    3
    Views:
    10,917
    yehuda54
    Feb 28, 2008
  3. javadude
    Replies:
    2
    Views:
    5,885
    Wendy Smoak
    Jun 30, 2005
  4. runescience
    Replies:
    0
    Views:
    1,439
    runescience
    Feb 9, 2006
  5. Replies:
    3
    Views:
    3,615
Loading...

Share This Page