In fact, this is how my request attributes were named, specificallybecause
of the structure of my data objects.  I realized that this was not ideal,
since only ip[0] is actually indexed in the page, and the rest:
itemPropertys[0].itemPropertyId it is always identical.  It was formatted
this way because the default object returned for the ItemPropertys object
was a list as well, but it only ever had one element.

I have now changed the objects so that the ip object stores all of the
data itself, instead of having the nested value object.  Thus, my indexed
form properties look like:

ip[0].itemPropertyId
ip[0].itemPropertyValue


But I have still been recieving the same error.

I have two questions:

1) Why is this getter structured this way?  I have seen it suggested to do
it this way once before, but I don't understand why..

public ItemProperties getIp(int index) {
   while (index >= ips.size()) {
     ips.add(new ItemProperties());
   }
   return (ItemProperties)ips.get(index);
 }


2) if I named my getters and setters as you have suggested, how does the
struts action know that it is supposed to use them to populate the form
bean?  getIp() makes sense, but getIps does not....


Thanks for the suggestions

Cameron

>
>
>
>
>
> Cameron,
>
> Are you sure that your request attributes are named that way?  I read
> that as a 3 dimensional table...do you really have that in your page?
>
> If you are getting those request attributes, then I'm stumped, but I'd
> love to know the answer :-)
>
> Otherwise...you need a getter/setter for the collection which get s and
> sets a collection of "bean" objects.  You also need a get method for a
> single element in your indexed collection.  For example:
>
> public Collection getIps() {return ips;}
> public void setIps(ArrayList ips) {this.ips = ips;}
>
> public ItemProperties getIp(int index) {
>   while (index >= ips.size()) {
>     ips.add(new ItemProperties());
>   }
>   return (ItemProperties)ips.get(index);
> }
>
> Nick
>
>
>
>
>                       "Cameron Hickey"
>
>             <[EMAIL PROTECTED]        To:
> "'Struts Users Mailing List'"
> <[EMAIL PROTECTED]>
> com>                     cc:
>
>
>                                                Subject:  writing an
> actionform for nested
> indexed properties
>
>                       08/21/2003 10:00
>
>             AM
>
>                         Please respond to
>
>                                     "Struts Users
>
>
> Mailing List"
>
>
>
>
>
>
>
>
> I am trying to write an actionform which will properly handle an array
> of indexed properties which look like this:
>
> ip[0].itemPropertys[0].itemPropertyId
> ip[0].itemPropertys[0].value
>
> ip[1].itemPropertys[0].itemPropertyId
> ip[1].itemPropertys[0].value
>
> etc...
>
>
> In my Action form, what getters and setters do I need?
>
> This is what I have so far:
>
> public List getIp() { return ip;}
> public void setIp(List ipList) {ip = ipList;}
>
> public List getItemPropertys(int idx) {return (List) ip.get(idx); }
> public void setItemPropertys(int idx,ItemProperty ipe)
> {ip.set(idx,ipe);}
>
> public ItemProperty getItemProperty(int idx, List ipl) {return
> (ItemProperty) ipl.get(idx);}
> public void setItemProperty(int idx,List ipl, ItemProperty tip)
> {ipl.set(idx,tip);}
>
> public String getValue(ItemProperty tip) {return tip.getValue();}
> public void setValue(String s, ItemProperty tip) {tip.setValue(s);}
>
> public int getItemPropertyId(ItemProperty tip) {return
> tip.getItemPropertyId();}
> public void setItemPropertyId(int i, ItemProperty tip)
> {tip.setItemPropertyId(i);}
>
>
>
>
> but when I try to submit the form, I get this error:
>
> <ERROR>
> java.lang.NullPointerException
>              at
> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
> ils.java:497)
>              at
> org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
> ils.java:410)
>              at
> org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUti
> ls.java:729)
>              at
> org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav
> a:780)
>              at
> org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:793)
>              at
> org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
> </ERROR>
>
> which I assume is coming from the fact that I don't have all the right
> getters and setters available, since it must be trying to call one that
> does not exist (thus the null pointer).
>
> Is this right?
>
> Should I have other getters and setters?
>
>
>
> THANKS FOR ANY HELP!!
>
> Cameron
>
>
> --------------------------------------------------------------------- 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