struts formbean array size dynamically

U

Uwe Voigt

Is it possible to set the size of a DynaActionForm array or list
property depending on the number of entries within the request
parameter values belonging to one request parameter name?
I always get arrays of size 0.
Thanks!
 
S

Sudsy

Uwe said:
Is it possible to set the size of a DynaActionForm array or list
property depending on the number of entries within the request
parameter values belonging to one request parameter name?
I always get arrays of size 0.
Thanks!

You'll have to provide code samples since I've used this approach before
and it's always worked for me. Just make sure that you specify the empty
square brackets in the type attribute of the form-property element and
cast the return from DynaActionForm#get to the appropriate array type.
I can send you some working code but don't want to annoy others by
posting to the ng.
 
U

Uwe Voigt

Ok, here are the snippets
this is from struts-config:
<form-beans>
<form-bean name="bean"
type="org.apache.struts.action.DynaActionForm">
<form-property name="orderItems" type="test.OrderItem[]">
</form-property>
</form-bean>
</form-beans>

the scope is request

this is from the jsp:
<logic:iterate indexId="index" offset="0" id="item"
type="test.OrderItem" name="bean" property="orderItems">
<tr><td><html:text name="bean" property='<%= "orderItems[" + index +
"].quantity.amount" %>'/>&nbsp;<html:link action='<%=
"/deleteItem.do?orderId=" + orderNo + "&itemId=" +
item.getOrderItemNo() %>'><html:img src="images/trash.gif" width="13"
height="13" alt="delete" border="0"/></html:link></td></tr>
</logic:iterate>

I put the array into the bean, this direction is ok.
But on a request, where orderItems[0].quantity.amount=[2] is a
request parameter key value pair, a new array is constructed with an
initial size of zero. When debugging I saw no code that actually takes
the size of the request parameter value array to resize or override
the array with an appropriate size within the bean.

It finally ends up within org.apache.commons.beanutils.PropertyUtils
which tries to get a value from
org.apache.struts.action.DynaActionForm.get(String name, int index)
where the value of the array has the initial size of zero.

I thought that this must work because nearly everyone needs dynamic
array sizes. So it must be me doing anything wrong?
Thanks
 
U

Uwe Voigt

fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
 
S

Sudsy

Uwe said:
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default

It works for arrays of basic objects like java.lang.String but doesn't
extend to custom classes. You end up overriding the indexed get but
must extend your internal array automagically as the requests are not
guaranteed to occur in numerical sequence. You might see getXXX( 2 ),
getXXX( 1 ), getXXX( 3 ), getXXX( 0 ), for example. Your indexed set
doesn't get called as the mutators are called directly on the objects
returned by the indexed get.
It gets gnarly in there, doesn't it?
 
Joined
May 8, 2006
Messages
1
Reaction score
0
Uwe Voigt said:
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
Sudsy <[email protected]> wrote in message news:<[email protected]>...
> Uwe Voigt wrote:
> > Is it possible to set the size of a DynaActionForm array or list
> > property depending on the number of entries within the request
> > parameter values belonging to one request parameter name?
> > I always get arrays of size 0.
> > Thanks!

>
> You'll have to provide code samples since I've used this approach before
> and it's always worked for me. Just make sure that you specify the empty
> square brackets in the type attribute of the form-property element and
> cast the return from DynaActionForm#get to the appropriate array type.
> I can send you some working code but don't want to annoy others by
> posting to the ng.


Hi
I am facing the same problem as faced by Uwe Voigt, i am not getting how to override DynaActionForm . CAn i get a code snippet to know how to override DynaActionForm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top