commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Dunn" <greg.d...@mo.nisc.cc>
Subject RE: [BEANUTILS] DynaBeans as DTOs used with JSTL?
Date Tue, 28 Oct 2003 23:15:45 GMT

Does JSTL work with plain DynaBeans now?

Greg 


-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org]
Sent: Tuesday, October 28, 2003 11:26 AM
To: Jakarta Commons Users List
Subject: Re: [BEANUTILS] DynaBeans as DTOs used with JSTL?


otisg wrote:

>Hello,
>
>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
>DynaBeans.
>
>The reason why I think that DynaBeans and JSTL may not mesh, is
>that JSTL accesses bean properties in JavaBeans-style (foo.bar
>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 
class:

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

Now, the EL expression "foo.map.bar" 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.

>Thanks,
>Otis
>
>  
>

Craig McClanahan



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message