struts formbean array size dynamically

Discussion in 'Java' started by Uwe Voigt, Jun 5, 2004.

  1. Uwe Voigt

    Uwe Voigt Guest

    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!
     
    Uwe Voigt, Jun 5, 2004
    #1
    1. Advertising

  2. Uwe Voigt

    Sudsy Guest

    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, Jun 6, 2004
    #2
    1. Advertising

  3. Uwe Voigt

    Uwe Voigt Guest

    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.
     
    Uwe Voigt, Jun 6, 2004
    #3
  4. Uwe Voigt

    Uwe Voigt Guest

    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.
     
    Uwe Voigt, Jun 7, 2004
    #4
  5. Uwe Voigt

    Sudsy Guest

    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?
     
    Sudsy, Jun 7, 2004
    #5
  6. Uwe Voigt

    Hema

    Joined:
    May 8, 2006
    Messages:
    1

    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
     
    Hema, May 8, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wendy S
    Replies:
    0
    Views:
    981
    Wendy S
    Jun 28, 2003
  2. Xavier Tarrago
    Replies:
    0
    Views:
    1,451
    Xavier Tarrago
    Jun 30, 2003
  3. Eduardo
    Replies:
    4
    Views:
    9,897
    Andrew Thompson
    Sep 19, 2004
  4. Squishy
    Replies:
    1
    Views:
    11,963
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,736
    Michael Jung
    May 25, 2008
Loading...

Share This Page