commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From otisg <>
Subject Re: RE: [BEANUTILS] DynaBeans as DTOs used with JSTL?
Date Wed, 29 Oct 2003 12:11:12 GMT

Get your own "800" number
Voicemail, fax, email, and a lot more

---- On Tue, 28 Oct 2003, Greg Dunn (

> Does JSTL work with plain DynaBeans now?

I _think_ you should be able to do:
  <c:out value="$yourbean["quasiPropertyButReallyMapKey"]"/>

If that returns some JavaBean-style object, then you could still
access its properties with a dot operator:

  <c:out value="$yourbean["Key"].someProperty"/>

I have not tested this yet.
It would be nicer if I could just access DynaBeans from JSTL
like this:

  <c:out value="$yourbean.Key.someProperty"/>

But that should not work currently.
If I understand things correctly, one of the Beanutils classes
could be extended, and in its subclass a public Map getMap()
method could be added, like Craig described below.  This should
then allow access like this:

  <c:out value="$"/>

I _think_, but I am not sure.  It would be nice if somebody
could confirm this or correct me.  In the mean time, I will go
try doing this myself.


> -----Original Message-----
> From: Craig R. McClanahan []
> 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
> >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
> >elegant and simple chunk of data from Business Logic objects
> >the View layer.
> >I am not concerned with the network/efficiency between the
> >I am only considering these DTOs in order to avoid the
> >of inellegant 'hashes of hashes of list of foo and bar and
> >blah' structures to the View layer.
> >
> >DynaBeans sound like a good idea at first, but because the
> >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,
> >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
> >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
> >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
> class:
>     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.
> >Thanks,
> >Otis
> >
> >  
> >
> Craig McClanahan

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

View raw message