This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes setIndexedProperty errors after reposting form data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "setIndexedProperty errors after reposting form data" Watch "setIndexedProperty errors after reposting form data" New topic
Author

setIndexedProperty errors after reposting form data

delta beta
Greenhorn

Joined: Nov 05, 2008
Posts: 4
My problem is when struts attempts to assign a value to an array defined in my action form, it throws a null pointer exception. This is before the Action.execute() is invoked. My approach is to iterate through a collection to selectively render data. The collection is maintained in lockstep w/the form arrays -this supports evaluating data stored in the database which is not relevant to the initial data entry "state", using an iterator.
The form array is used for rendering data only -the data are entered using other fields -submitted- and then reposted via the form array;
this approach is intended to allow the array to grow/shrink on demand, again using another set of fields to handle the data record input. Can I "re-submit" this form array data?
I would think this would be a pretty standard utilization.

My initial form entry works fine as does the subsequent rendering of that data -I repost the form ( after updating all form fields ) and the data is correct.
What I see in the debugger is that the form array is null when this request is submitted.

Here's a snippet of what I use to display the form data arrays:

<logic:iterate id="collectionAdjustmentsListRec" name="sessionCollectionAdjustments" indexId="ctr">
<tr>
<td align="left">
<html:text size="8" maxlength="8" property='<%= "collectionAdjustmentTypeCodes[" + ctr + "]" %>' />
</td>
...

Problem is that the collectionAdjustmentTypeCodes array is null after submitting the form when struts attempts to populate the form.
Can I not use the request form ( parameter ) to handle this? And will using indexed array (action form )value not work? If so,
should I be using beans other than the ActionForm ( parameter ) beans?
Will the container not submit my form field ( "collectionAdjustmentTypeCodes" ) to be processed as a parameter? I thought
the servlet container automatically instantiates parameter arrays, though apparently this is not the same.


The errors occur within the following:

BeanUtils.setProperty calls setIndexedProperty and it fails because the "array assignment" (shown returns a null value) and thus the
if (!array.getClass().isArray()) { throws an exception. Sh

Within the debugger, this array is null.

org.apache.commons.beanutils.BeanUtils:
public void setProperty(Object bean, String name, Object value)


.... setIndexedProperty(...)

--------------------------------------------------------------------------------------
org.apache.commons.beanutils.PropertyUtils:
public void setIndexedProperty(Object bean, String name,
int index, Object value)
...
...
...
// Call the property getter to get the array or list
Object array = invokeMethod(readMethod, bean, new Object[0]);



Any help is appreciated.

[ November 25, 2008: Message edited by: delta beta ]

[ November 25, 2008: Message edited by: delta beta ]

[ November 25, 2008: Message edited by: delta beta ]

[ November 25, 2008: Message edited by: delta beta ]
[ November 25, 2008: Message edited by: delta beta ]
delta beta
Greenhorn

Joined: Nov 05, 2008
Posts: 4
Did any of that make sense to anyone? If not, I'll try a condensed version:

my request fails when struts attempts to populate array values using the following:
<logic:iterate id="collectionAdjustmentsListRec" name="sessionCollectionAdjustments" indexId="ctr">
<tr>
<td align="left">
<html:text size="8" maxlength="8" property='<%= "collectionAdjustmentTypeCodes[" + ctr + "]" %>' />
</td>

abbreviated stack trace:

[http-8080-Processor25] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[testsvr].[/JCFullePA_collections].[action] - Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtilsBean.setIndexedProperty(PropertyUtilsBean.java:1414)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1016)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:467)
It throws a NullPointerException

I stepped through the code and see where the collectionAdjustmentTypeCodes aray is null, after submitting the request. Note: the above reference to collectionAdjustmentTypeCodes[" + ctr + "]" renders correctly -I place the "collectionAdjustmentTypeCode" into the ActionForm array and then forward to that jsp page. It throws the exception when this form is then submitted. I'm not sure what I'm doing wrong, fundementally. Is this just new parameter data? Such that struts would actually be looking for a [form] getter of the form getCollectionAdjustmentTypeCodes[0..n]? My fallback is to use a message bean tag and report the value directly from the collection business object, thus keeping the value w/in an "attribute". This has other implications, though it is a feasible work-around. Any input is appreciated.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Do you have a setter for an indexed property in your action form?
delta beta
Greenhorn

Joined: Nov 05, 2008
Posts: 4
Not an explicit setter for an indexed property, per se. I just have the setter for the array itself. I'll look into this. Thanks.
Gj Joshi
Greenhorn

Joined: Mar 03, 2009
Posts: 2
delta beta wrote:Not an explicit setter for an indexed property, per se. I just have the setter for the array itself. I'll look into this. Thanks.


Hello, I am facing issue. Have you got any solution on this?
 
Don't get me started about those stupid light bulbs.
 
subject: setIndexedProperty errors after reposting form data