You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Karl <ka...@webartjapan.com> on 2003/03/05 05:16:04 UTC

Problems with the iterate tag

I'm trying to get my jsp page to iterate over a collection of objects, 
printing one object property (data) on every line.

I've tried implementing the following:

test.jsp:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <logic:iterate id="element" name="testContainer" property="testData">
            <bean:write name="element" property="data"/>.<br/>
        </logic:iterate>
        END<br/>
    </body>
</html:html>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


TestForm.java:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
package com.somewhere;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import java.util.*;

public final class TestForm extends ActionForm {

    private Collection myCollection;

    {
        myCollection = new Vector();
        myCollection.add(new TestData("1"));
        myCollection.add(new TestData("two"));
        myCollection.add(new TestData("III"));
    }

    public Collection getTestData() {
        return myCollection;
    }
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


TestData.java:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
package com.somewhere;

public final class TestData {

    private String myData;

    public TestData(String value) {
        myData = value;
    }

    public String getData() {
        return myData;
    }
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


struts-config.xml:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
<struts-config>
    <form-beans type="org.apache.struts.action.ActionFormBean">
        <form-bean name="testContainer" type="com.somewhere.TestForm" />
    </form-beans>
    <action-mappings type="org.apache.struts.action.ActionMapping">
        <action path="/do_test" forward="/test.jsp" name="testContainer" 
validate="false"/>
    </action-mappings>
</struts-config>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


However, when I try to run this, it fails:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
org.apache.jasper.JasperException: No getter method for property data of bean 
element
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


It must be something with either "element" being the id of the iteration or 
the name of the write tag, but I can't see any other way that I'd tell it to 
access the correct data.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Problems with the iterate tag

Posted by James Mitchell <jm...@apache.org>.
Why are you specifying property="data"?

>  <bean:write name="element" property="data"/>.<br/>
                              ^^^^^^^^^^^^^^^

Try removing that.

--
James Mitchell
Web Developer/Struts Evangelist
http://jakarta.apache.org/struts/

"People demand freedom of speech to make up for the freedom of thought
which they avoid."
    - Soren Aabye Kierkegaard (1813-1855)




> -----Original Message-----
> From: Karl [mailto:karl@webartjapan.com] 
> Sent: Tuesday, March 04, 2003 11:16 PM
> To: Struts Users Mailing List
> Subject: Problems with the iterate tag
> 
> 
> I'm trying to get my jsp page to iterate over a collection of 
> objects, 
> printing one object property (data) on every line.
> 
> I've tried implementing the following:
> 
> test.jsp:
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> 
> <html:html>
>     <head>
>         <title>Test</title>
>     </head>
>     <body>
>         <logic:iterate id="element" name="testContainer" 
> property="testData">
>             <bean:write name="element" property="data"/>.<br/>
>         </logic:iterate>
>         END<br/>
>     </body>
> </html:html>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> 
> TestForm.java:
> 
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> package com.somewhere;
> 
> import javax.servlet.http.HttpServletRequest;
> import org.apache.struts.action.*;
> import java.util.*;
> 
> public final class TestForm extends ActionForm {
> 
>     private Collection myCollection;
> 
>     {
>         myCollection = new Vector();
>         myCollection.add(new TestData("1"));
>         myCollection.add(new TestData("two"));
>         myCollection.add(new TestData("III"));
>     }
> 
>     public Collection getTestData() {
>         return myCollection;
>     }
> }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> 
> TestData.java:
> 
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> package com.somewhere;
> 
> public final class TestData {
> 
>     private String myData;
> 
>     public TestData(String value) {
>         myData = value;
>     }
> 
>     public String getData() {
>         return myData;
>     }
> }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> 
> struts-config.xml:
> 
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> <struts-config>
>     <form-beans type="org.apache.struts.action.ActionFormBean">
>         <form-bean name="testContainer" 
> type="com.somewhere.TestForm" />
>     </form-beans>
>     <action-mappings type="org.apache.struts.action.ActionMapping">
>         <action path="/do_test" forward="/test.jsp" 
> name="testContainer" 
> validate="false"/>
>     </action-mappings>
> </struts-config>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> 
> However, when I try to run this, it fails:
> 
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> org.apache.jasper.JasperException: No getter method for 
> property data of bean 
> element
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> 
> It must be something with either "element" being the id of 
> the iteration or 
> the name of the write tag, but I can't see any other way that 
> I'd tell it to 
> access the correct data.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org