Discussions

Web tier: servlets, JSP, Web frameworks: Formatter implementation from Jakarta Pitfall by Bill Dudney

  1. I've successfully implement the "Formatter" solution provided by Dudney in Jakarta Pitfalls. At least for simple forms but I can't get it to work for nested beans.

    http://www.wiley.com/legacy/compbooks/dudney/jakarta/index.html

    When I execute the command: formHStr.populate(formHDO);
    I get the following error message:
    ERROR http-8080-Processor24 org.apache.commons.beanutils.PropertyUtils - Method invocation failed.
    java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
    at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
    at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:577)
    at com.wolmerica.tools.formatter.MasterForm.populateProperty(MasterForm.java:319)
    Any tips would be appreciated.
    Thank You
    Rich
  2. Rich,

    From the stack trace you provided, it looks like your code would need to call the PropertyUtils method setNestedProperty rather than setSimpleProperty. If you'd like to see a more comprehensive implementation, you might want take a look at my StrutsLive open source project, at http://strutslive.dev.java.net . In fact you can download strutslive.jar and add to your project and it will automatically populate your object graph for you, while posting appropriate error messages for failed conversions, without you having to write any additional code.

    StrutsLive is currently in use in a number of production apps, including several developed by Booz Allen and The Analysis Corp. for the U.S. government.

    Regards,

    Jonathan