You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2002/03/27 17:59:48 UTC

DO NOT REPLY [Bug 7521] New: - BeanUtils.populate() does not handle nested properties of dynabean

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=7521>.
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=7521

BeanUtils.populate() does not handle nested properties of dynabean

           Summary: BeanUtils.populate() does not handle nested properties
                    of dynabean
           Product: Commons
           Version: Nightly Builds
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Bean Utilities
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: amandava@yahoo.com


I am trying to use the new DynaActionForm (from Struts beta1) with nested
properties, and it seems like that DynaActionForm ignores the nesting stuff.
While checking out code, it appears like BeanUtils.populate() does not seem
to traverse the property nesting. It works ok if I switch to regular form bean.

Here are more details of the issue:

Form bean configuration from struts-config:
    <form-bean      name="cart" 
                    type="MyDynaActionForm"
                    className="MyFormBeanConfig">
      <form-property name="name" type="java.lang.String"/>
      <form-property name="items" type="ShoppingItem[]"/>
    </form-bean>

MyDynaActionForm is an extension to prevent "reset()" from clearing "items"
array.
MyFormBeanConfig is an extension to recognize MyDynaActionForm class name as
dynamic.
ShoppingItem is a bean with 3 properties - (String)id, (int)quantity, and 
(boolean) remove.

Here is how my JSP looks:
<nested:form action="/updateCart">
<nested:text property="name"/>
<TABLE>
  <nested:iterate id="it" property="items">
  <TR>
    <TD><nested:text property="id"/></TD>
    <TD><nested:text property="quantity"/></TD>
    <TD><nested:checkbox property="remove"/></TD>
  </TR>
  </nested:iterate>
</TABLE>

<nested:submit property="Update" value="Update"/>
</nested:form>

Generated html looks like (if I had two items in the shoppingItems array):
<form name="cart" method="POST" action="/cart/updateCart.do">
<input type="text" name="name">

<TABLE>
  <TR>
    <TD><input type="text" name="items[0].id" value="first"></TD>
    <TD><input type="text" name="items[0].quantity" value="1"></TD>
    <TD><input type="checkbox" name="items[0].remove" value="on"></TD>
  </TR>
  
  <TR>
    <TD><input type="text" name="items[1].id" value="second"></TD>
    <TD><input type="text" name="items[1].quantity" value="2"></TD>
    <TD><input type="checkbox" name="items[1].remove" value="on"></TD>
  </TR>
  
</TABLE>

<input type="submit" name="Update" value="Update">
</form>

So, when the form is submitted as is,
 BeanUtils has to populate "items[0].id" to "first" etc.

It invokes the equivalent of following on the dynaform bean.
set("items", 0, "first")  instead of get("items", 0).setId("first").

To be more precise, it invokes:
   PropertyUtils.setIndexedProperty(bean, //the dynabean
                                    dynaName, // "items"
                                    index, // 0
                                    newValue // "first"
                                   );
It should really have done
  Object subbean = PropertyUtils.getIndexedProperty(bean, // the dynabean
                                                    dynaName, //"items"
                                                    index); //0
                   PropertyUtils.setProperty(subbean, 
                                             dynaName, // "id"
                                             value);//"first"

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>