Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer setting values to an object list

 
Swathi Ram
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swathi Ram
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic