commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [BEANUTILS] DynaBeans as DTOs used with JSTL?
Date Tue, 28 Oct 2003 17:25:54 GMT
otisg wrote:

>I am trying to come up with a simple and flexible solution for
>implementing DTOs and I am considering DynaBeans in order to
>dynamically create JavaBeans that could play the DTO role,
>instead of creating a number of dumb JavaBean classes.
>In my context, these DTOs would be used as the means to pass an
>elegant and simple chunk of data from Business Logic objects to
>the View layer.
>I am not concerned with the network/efficiency between the two.
>I am only considering these DTOs in order to avoid the passing
>of inellegant 'hashes of hashes of list of foo and bar and blah
>blah' structures to the View layer.
>DynaBeans sound like a good idea at first, but because the View
>layer in my case uses JSTL, I am not sure if I can use
>The reason why I think that DynaBeans and JSTL may not mesh, is
>that JSTL accesses bean properties in JavaBeans-style (
>is translated to foo.getBar()).
>On the other hand, access to properties in a DynaBean is via
>set(String) and get(String) methods, which the View layer using
>JSTL could not invoke.
>So my questions are:
>- Am I wrong to even consider DynaBeans for this?
>- Am I wrong in assuming that DynaBeans and JSTL can't play
>together nicely?
>- It sounds to me like it should be possible to write an Adapter
>for DynaBeans, maybe using java.lang.Proxy(?), in order to
>convert foo.getBar() calls from JSTL to foo.get("bar") that
>would work with a DynaBean.
>- Has anyone done this?

Struts uses DynaBeans as one way to create form beans (sort of a DTO for 
the view tier).  In order to interoperate better with JSTL, one of the 
things we did there was add the following method to the DynaActionForm 

    public Map getMap() {
        return (dynavalues); // Return the internal HashMap of 
name-value pairs

Now, the EL expression "" ends up calling foo.getMap() to 
return a map, and then gets the "bar" value from the map.

Outside of Struts, you could easily create your own DynaBean base class 
that has such a method, and end up with the same capability.


Craig McClanahan

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message