Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   struts formbean array size dynamically (http://www.velocityreviews.com/forums/t134127-struts-formbean-array-size-dynamically.html)

Uwe Voigt 06-05-2004 10:25 PM

struts formbean array size dynamically
 
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!

Sudsy 06-06-2004 01:13 AM

Re: struts formbean array size dynamically
 
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.


Uwe Voigt 06-06-2004 07:42 AM

Re: struts formbean array size dynamically
 
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



Sudsy <bitbucket44@hotmail.com> wrote in message news:<40C26F9E.3050406@hotmail.com>...
> 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.


Uwe Voigt 06-07-2004 08:14 AM

Re: struts formbean array size dynamically
 
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
Sudsy <bitbucket44@hotmail.com> wrote in message news:<40C26F9E.3050406@hotmail.com>...
> 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.


Sudsy 06-07-2004 12:59 PM

Re: struts formbean array size dynamically
 
Uwe Voigt wrote:
> 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?


Hema 05-08-2006 05:15 AM

Re: struts formbean array size dynamically
 
Quote:

Originally Posted by Uwe Voigt
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
Sudsy <bitbucket44@hotmail.com> wrote in message news:<40C26F9E.3050406@hotmail.com>...
> 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


All times are GMT. The time now is 04:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.