Formatter implementation from Jakarta Pitfall by Bill Dudney


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.

    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(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(
    at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(
    at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(
    Any tips would be appreciated.
    Thank You
  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 . 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.