• 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

Indexed properties - I am totally stuck

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help in submitting a form which uses Indexed properties of Struts.

The ActionForm is Like this:

public class TestsupplementForm extends ValidatorActionForm {


private String CaseKey ;
/*
other properties goes here
*/


private LabResults[] data;



public LabResults[] getData() {
return vani;
}

public void setData(LabResults[] data) {
this.data = data;
}
}


public class LabResults {


private String DiseaseGroup ;
private String Disease_Code;


public String getDisease_Code() {
return Disease_Code;
}

public void setDisease_Code(String disease_Code) {
Disease_Code = disease_Code;
}

public String getDiseaseGroup() {
return DiseaseGroup;
}

public void setDiseaseGroup(String diseaseGroup) {
DiseaseGroup = diseaseGroup;
}

}

The Struts Config entry is like this:
<form-bean name="TestSupplement" type="TestsupplementForm "></form-bean>

<action name="TestSupplement" path="/testSupplement" scope="request" type="TestAction" parameter="method" validate="false">
<forward name="testSupplAddRow" path="/testSupplement.do?method=doAddLab" />
</action>

I am able to display my dynamic form which goes like this
<html>
<head>
<title>Communicable Disease Electronic Surveillance System</title>
</head>
<link rel="stylesheet" type="text/css" href="jsp/css/cdess.css">
<body class="BodyFont" >
<form name="TestSupplement" method="POST" action="/testSupplement.do" enctype="application/x-www-form-urlencoded">

<input type="text" name="data[0].diseaseGroup" value="31">

<input type="text" name="data[1].diseaseGroup" value="31">

<input type="text" name="data[2].diseaseGroup" value="31">

<input type="submit" name="method" accesskey="S" value="doAddLab">
</form>

</body>
</html>

When I submit my page using addLab I get the following error:
java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
.............................

Your help is greatly appreciated.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ,


This occurs if there are multiple formbean in the same application. which means if a single attribute is used across multiple formbean.

so in that case, struts cannot find out the setter and getters of individual attributes for different requests.

so , my advice is check the formbean in your application and if you mind any attribute is repeated in someother formbean also, then better have a unique name across the formbean, simple change the attribute name which is repeated.


you can rectify the exceptions
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What this message means is that when your JSP accesses individual members of a collection or array, you must provide an indexed getter for that collection in your ActionForm. By this, I mean a getter that takes an integer as a parameter, and returns a single element of the collection or array.

Something like this:

 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic