• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with indexed properties

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know that this topic has been discussed earlier and i already have one version of indexed properties on another jsp that runs - but this time i have serious trouble.
I have an ActionForm-Bean which contains a String-Array of Beans.
----CODE----
private ListBean[] beans;
private ListBean bean;
public ListBean[] getBeans()
{
return beans;
}
public void setBeans(int index, ListBean bean)
{
beans[index] = bean;
}
public void setBean(int index, ListBean value)
{
beans[index] = value;
}
public ListBean getBean(int index)
{
return (ListBean) beans[index];
}
--Code end
This code in my jsp look like:
<html:form action="list.do?method=copy" >
<table width="400" border="0" >
<logic:iterate id="speech"
indexId="ctr"
name="CopyListFormBean"
property="beans"
type="istd.client.td.beans.ListBean" >
<tr>
<td width="20%">
<html:checkbox property='<%= "beans[" + ctr + "].copy" %>' />
</td>
<td>
<bean:write name="CopyListFormBean" property='<%= "beans[" + ctr + "].sprache" %>' />
<html:hidden property='<%= "beans[" + ctr + "].sprachId" %>' />
<html:hidden property='<%= "beans[" + ctr + "].listId" %>' />
</td>
</tr>
</logic:iterate>
<tr>
<td>
 
</td>
<td>
<html:submit />
</td>
</tr>
</html:form>
When Submitting the Form i get the 'popular' ErrorMessage
java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:497)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:410)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:749)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:780)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:793)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
Any Idea? I'm totally frustrated - maybe i need a break.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem.
I solved it by initializing the phone array in the setter method.
For Example:
private String[] phone = null;
public void setPhone(int index, String value) {

try
{
if(phone==null) {
phone = new String[100];
}
phone[index]=value;
}
catch (Exception e) { System.out.println("Exception in setPhone : " + e);}
}
Thanks
Priya
 
Always look on the bright side of life. At least this ad is really tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic