Atta,

The complaint you are getting is because the property "fruit" is not a
property of the "oneF" bean.  That the oneF object is not a bean with
properties will give you problems.  Depending on your goal, you need to do
something different.  What are you trying to do?

I'm off work in a minute, but I'll check messages at home later this
evening and see if I can help at all.
Nick



                                                                                       
                                                
                      "atta-ur rehman"                                                 
                                                
                      <[EMAIL PROTECTED]        To:       "Struts Users Mailing List" 
<[EMAIL PROTECTED]>                  
                      com>                     cc:                                     
                                                
                                               Subject:  Re: Indexed Properties        
                                                
                      07/28/2003 03:44                                                 
                                                
                      PM                                                               
                                                
                      Please respond to                                                
                                                
                      "Struts Users                                                    
                                                
                      Mailing List"                                                    
                                                
                                                                                       
                                                
                                                                                       
                                                




Thanks very much Nick! It was indeed helpful. I was missing getter/setter
for individual list items!

now my form has following methods:
private String[] fruit = {"Apple", "Orange", "Banana"};

public List getFruits() {

return Arrays.asList(this.fruit);

}

public void setFruits(List l) {

this.fruit = (String[]) l.toArray();

}


public String getFruit(int index) {

if (this.fruit == null) return "null";

return this.fruit[index];

}

public void setFruit(int index, String f) {

this.fruit[index] = f;

}

my JSP has following has this html:iterator:

<logic:iterate name="theForm" property="fruits" id="oneF"
type="java.lang.String" >
   <tr>
    <td align="center">
     hi!
    </td>
    <td>
     <html:text property="fruit" name="oneF" indexed="true" />
    </td>
   </tr>
  </logic:iterate>

and exception i get is this:

javax.servlet.jsp.JspException: No getter method for property fruit of bean
oneF
             at
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)


i think it has to do with the fact that my individual fruit is a string
object rather than being a bean in itself if some getter method(s)?

can you see what's going wrong!

Thanks again.

ATTA

----- Original Message -----
From: "Nicholas L Mohler" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, July 28, 2003 11:58 AM
Subject: Re: Indexed Properties


>
>
>
>
>
> Atta,
>
> You can use indexed properties in your ActionForm class.  The key is
having
> all of the correct methods in your form class.
>
> 1)  Getter and setter:  You need a get/Set method for the collection that
> you refer to in your jsp.  for example:
> public Collection getLocations()
> public void setLocations(Collection locs)
>
> 2) Getter and setter for one instance in the collection.  The name that
you
> use must match the name you define in your jsp as a single instance from
> the collection (specified as the id).  For example:
>     <logic:iterate name="locations" id="oneLocation"
>             type="com.myco.toolkits.beans.Location">
>         <td>
>             <html:text name="oneLocation" property="locationName" indexed
> ="true"/>
>         </td>
>         <td>
>             <html:text name="oneLocation" property="locationAddress"
> indexed="true"/>
>         </td>
>     </logic:iterate>
>
> Your form should in this case have the following get/set methods:
> public com.myco.toolkits.beans.Location getOneLocation(int index)
> public void setOneLocation(int index, com.myco.toolkits.beans.Location
> oneLocation)
>
> Your code may never use either of the "oneLocation" methods, but they are
> important for Struts.  When your page is submitted, your two indexed
> properties will be submitted as oneLocation[ix].locationName &
> oneLocation[ix].locationAddress where ix is the index of the row (0-10
for
> example).  As Struts proceses the indexed items, Struts will use the
> "getOneLocation" method to get the Collection instance for the provided
> index.  This method must resize the collection as needed and then return
> the object for the provided index.  For example, if your collection has
no
> objects and the getter receives an index of 2, the method should load the
> first three (0, 1, 2) collection locations with an initialized object and
> return the third object.  Struts will then populate the appropriate
> property in that object.
>
> As an aside, I tend to use the ArrayList object as my collection type
when
> working with indexed properties, but I know that the Vector works equally
> well.  A simple array will work fine, but the logic to expand the size is
a
> little more involved.
>
> Let me know if this helps.
> Nick
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to