• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic