On Sat, 14 Apr 2001, Jim Crossley wrote:

> See below.
> 
> "Craig R. McClanahan" wrote:
> > 
> > > 2) I have a bean that has a collection of Phone objects, accessible via
> > > its getPhones() method.  Shouldn't I be able to return EITHER a Phone[]
> > > or a java.util.Collection?  The following element works fine when a
> > > Collection is returned, but I get an error ("No getter method for
> > > property phones of bean myForm") when a Phone[] is returned.
> > >
> > >     <logic:iterate id="phone" name="myForm" property="phones" >
> > >     <tr>
> > >       <td>
> > >         <bean:write name="phone" property="type" />
> > >       </td>
> > >       <td>
> > >         <html:text name="phone" property="number" />
> > >       </td>
> > >     </tr>
> > >     </logic:iterate>
> > >
> > > Thanks in advance.
> > >
> > 
> > Can you post the actual getPhones() method of your form bean in the case
> > where this fails?
> 
> It's pretty typical, in that it returns an actual Phone[] member:
> 
>   public Phone[] getPhones() { return this.phones; }
> 
> However, the "setter" was a little different:
> 
>   public void setPhones (Collection c) { ... }
> 
> I came to the conclusion that Struts wasn't too happy dealing one type
> for the getter's return and another for the setter's parameter.  I
> wasn't able to confirm that by looking at the source, though.
> 

Well, you are correct that Struts won't like that much ... but it's really
because Java won't either.  You are violating the JavaBeans Specification
on property names when you try this kind of thing.

Craig McClanahan


Reply via email to