wood burning stoves 2.0*
The moose likes Struts and the fly likes Null pointer setting values to an object list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Null pointer setting values to an object list" Watch "Null pointer setting values to an object list" New topic
Author

Null pointer setting values to an object list

Swathi Ram
Greenhorn

Joined: Sep 18, 2007
Posts: 27
I have an array of type object
private Job jobList[] = null;

noJobs=1; (this value is dynamic and the value gets picked up correctly.)

jobList = new Job[noJobs];
for(int i=0;i<noJobs;i++) {
jobList[i] = new Job();
}
I am initializing it in my action class.
In my object I can have multiple jobs, so I'm displaying the fields for each job using an iterator in the jsp.
After entering the values and submitting the form.........it is not setting the values in the action class.
for (int i=0;i<jobList.length;i++)
{
Job j = (Job)jobList[i];
System.out.println("Job Type"+j.getJobType());
}

If it is a single Job object, it works fine.........but if I use an array of Jobs then it is not setting the values.
Anyone please help......
Thanks
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I suspect that the problem is that your form is saved in request scope and that when your form is submitted a brand new instance of your form is created with a null jobList. What exactly is editable on the screen? Are you using indexed properties?

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you have input fields for each element in the array, then you will need to use indexed properties. For more information on how to use indexed properties, see question 6 of this forum's FAQ.


Merrill
Consultant, Sima Solutions
Swathi Ram
Greenhorn

Joined: Sep 18, 2007
Posts: 27
In my jsp I'm using the index like this.

<s:form action="bulkpost.action" id="quickForm" method="POST" >
<s:iterator value="jobList" status="rowstatus">
<tr>
<td><s:select theme="simple" name="jobList[%{#rowstatus.index}].jobType" list="positions" emptyOption='true'/></td>
<td><s:select theme="simple" name="jobList[% {#rowstatus.index}].speciality" list="specialities" emptyOption='true'/></td>
</tr>
</s:iterator>

But I'm not getting the selected values to my action class . I'm trying to print the selected values in my action class as I metioned above.

Anyone please help......
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null pointer setting values to an object list