struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 10936] - No way to create arrays of non String/primitive types using DynaForms
Date Thu, 18 Jul 2002 05:21:09 GMT
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=10936>.
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=10936

No way to create arrays of non String/primitive types using DynaForms

craig.mcclanahan@sun.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX



------- Additional Comments From craig.mcclanahan@sun.com  2002-07-18 05:21 -------
It is actually possible to do this, but first a little background.

Something like "com.foobar.Person[10]" is not a valid Java variable declaration
(you are not allowed to include the array size).  Instead, you declare arrays in
a Java class like this:

  com.foobar.Person persons[] = null;

or

  com.foobar.Person persons[] = { ... }; // Some array initializer that
                                         // *implicitly* defines the array
                                         // size based on how many elements
                                         // you have listed.

The approach to solving this problem for DynaActionForms, if you want a
10-element array of "Person" objects, involves the following steps:

* Download a recent nightly build (after the support for an "initial"
  attribute that deals with array intializers was added).

* Define an org.apache.commons.beanutils.Converter implementation that
  knows how to convert a String into a Person, and register it with
  ConvertUtils.register().

* Set up your form bean like this:

  <form-bean name="foo">
    <form-property name="persons" type="com.foobar.Person[]"
     initial="{ '...', '...', '...', '...', '...',
                '...', '...', '...', '...', '...' }"/>
  </form-bean>

  where your Convert knows how to convert '...' into a Person object.
  Note that this is totally extensible to cover the types of Java
  objects you want to declare as array elements.  It also works for
  scalar objects of a custom type (i.e. type="com.foobar.Person").

Setting a size parameter only is bad for two reasons:

* This pattern is inconsistent with Java array declarations.

* It doesn't describe what in the heck you are supposed to initialize
  the array elements to.  Far better would be a way to create "real"
  Person objects (albeit with constant values).

* It restricts the initial array to only the number of elements
  you have specified, presumably with null values -- which is not
  much more helpful than not initializing the "persons" property itself.

The mechanism described above seems better suited to solving both of these
problems.  For the trivial case of wanting null objects, simply create a
Converter that converts a zero-length string ('') into a null).

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message