DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20535>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20535

Dynamically size arrays to allow array types in request scope DynaActionForm forms

           Summary: Dynamically size arrays to allow array types in request
                    scope DynaActionForm forms
           Product: Struts
           Version: 1.1 RC1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Controller
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


A number of posts to struts lists have concerned the use of array and list 
parameters in DynaActionForms. The standard response, "use LazyList", requires 
more overhead and is somewhat confusing to figure out. The other alternative is 
to put an instantiated array in session scope. This doesn't really work when 
the size of the array is unknown by the Action, and also means that the entire 
form has to be in session scope.

A much easier solution would be to have arrays auto-size themselves if they are 
not big enough. It seems to be that the DynaActionForm knows enough at run-time 
to handle this, and so I wrote a patch to do this. I'm attaching the diff 
below. Basically, when the form determines that it's dealing with an array 
value, it checks the length and extends the DynaActionForm's array size to 
match, copying existing values over if necessary.

I think it's pretty clean, and it does fix a bug (this definitely confuses 
people, and is not the expected behavior of DynaActionForm). I'm happy to 
continue to enhance as necessary if there are other known problems with array 
handling (I saw bug #19625, which provides similar functionality for lists, but 
haven't tried it yet).

Index: DynaActionForm.java
===================================================================
RCS file: /home/cvspublic/jakarta-
struts/src/share/org/apache/struts/action/DynaActionForm.java,v
retrieving revision 1.8
diff -r1.8 DynaActionForm.java
456a457,464
>                       // Dynamically create array if it's not big enough
>                       if (Array.getLength(prop) <= index) {
>                               Object oar = Array.newInstance(prop.getClass
().getComponentType(), index + 1) ;
>                               for (int i = 0 ; i < Array.getLength(prop) ; 
i++) {
>                                       Array.set(oar, i, Array.get(prop, i)) ;
>                               }
>                               prop = oar ;
>                       }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to