Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > struts formbean array size dynamically

Reply
Thread Tools

struts formbean array size dynamically

 
 
Uwe Voigt
Guest
Posts: n/a
 
      06-05-2004
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!
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      06-06-2004
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.

 
Reply With Quote
 
 
 
 
Uwe Voigt
Guest
Posts: n/a
 
      06-06-2004
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 <> wrote in message news:<>...
> 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.

 
Reply With Quote
 
Uwe Voigt
Guest
Posts: n/a
 
      06-07-2004
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
Sudsy <> wrote in message news:<>...
> 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.

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      06-07-2004
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?

 
Reply With Quote
 
Hema Hema is offline
Junior Member
Join Date: May 2006
Posts: 1
 
      05-08-2006
Quote:
Originally Posted by Uwe Voigt
fixed the problem by overriding DynaActionForm but still wonder why
that doesn't work by default
Sudsy <> wrote in message news:<>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
Accessing Struts Formbean attributes from JSP Squishy Java 1 07-03-2006 01:00 PM
How to populate a ArrayList FormBean attribute? Eduardo Java 4 09-19-2004 05:22 AM
Re: [Struts] Init formbean value before Initialisation? Xavier Tarrago Java 0 06-30-2003 09:08 AM
Re: [Struts] Init formbean value before Initialisation? Wendy S Java 0 06-28-2003 01:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57