commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Walter S. So" <>
Subject submitting a patch for BeanUtils
Date Mon, 07 Oct 2002 09:11:24 GMT

I am new to Jakarta Commons, and I don't use CVS to access the source code.  However, I would
to submit an enhancement for BeanUtils.

I'm using Struts 1.1b2 and BeanUtils 1.4 for my web app.  I created an ActionForm with an
attribute of Map[].  

public class NewForm extends ActionForm {  
    private Map[] map;

    public Map getMap(int index) { return[index];  }
    public Map[] getMap() { return; }
    public void setMap(int index, Map map) {[index] = map;  }
    public void setMap(Map[] map) { = map;   }    

Using this, I can populate the form with arbitrary keys and values like the following:
   ...  for (int index=0; index < 10; index++) {
            Map map = new HashMap(2);
            map.put("id", "1");
            map.put("groupid", "2");
            maps[index] = map;
        newForm.setMap(maps); ....

My JSP can now display the contents of each map as input elements:
<logic:iterate id="elem" name="newForm" property="map" type="java.util.Map">
   id: <html:text name="elem" indexed="true" property="id" />
   groupid: <html:text name="elem" indexed="true" property="groupid" />

The trouble is, when the form is submitted, the values inside the form elements are not updated.
As it is, BeanUtils does not change the values because it does not find a setter method for
or "groupid".  I patched BeanUtils with the following code:
       } else if ( target instanceof Map ) {  // line 844 
            Map map = (Map) target;
            map.put(name, ConvertUtils.convert(value));
       } else { ...

Now, changes made to the html form are saved in the ActionForm.  I hope that this patch can
added to the main distribution so others can also benefit.  I welcome any corrections and
to my suggestion, or if anyone knows better ways to do this. Thank you.


Walter S. So

Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
View raw message