struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-str...@ehatchersolutions.com>
Subject Re: dealing with HashMaps instead of beans
Date Thu, 20 Sep 2001 04:20:59 GMT
Check out BeanUtils:

http://cvs.apache.org/viewcvs/jakarta-commons/beanutils/src/java/org/apache/
commons/beanutils/BeanUtils.java?annotate=1.6

around line 330.... I think this is what you'd need, and its something that
the Struts tags would need to start using.  It might even be sort of already
in the works by others.  Anyone??

    Erik


----- Original Message -----
From: "Paul King" <Paul_King@vnp.com>
To: <struts-user@jakarta.apache.org>
Sent: Wednesday, September 19, 2001 11:29 PM
Subject: Re: dealing with HashMaps instead of beans


> Thanks Erik.  I'm looking for a general solution, so possible changes to
the
> Commons code could give me some hope.  This would be similar to behavior
NeXT
> used to implement to allow generic data bearing objects like HashMaps to
work
> interchangeably within their frameworks that managed bean-like objects.
>
> In addition to bean:write, I want to be able to use other std tags that
expect
> beans (e.g., html:options). Also, there are lots of tables loaded into
HashMaps
> in these apps. So... I don't think custom taglibs would be a good fit.
>
> paul
>
> Erik Hatcher wrote:
>
> > It'd only be a few line custom Taglib to write a tag that does a HashMap
key
> > lookup.   It's not possible with <bean:write> in its current form,
although
> > I believe the Commons BeanUtils code has recently been updated to
include
> > this kind of lookup, but its not necessary in order to write a simple
custom
> > tag.
> >
> >     Erik
> >
> > ----- Original Message -----
> > From: "Paul King" <Paul_King@vnp.com>
> > To: <struts-user@jakarta.apache.org>
> > Sent: Wednesday, September 19, 2001 4:45 PM
> > Subject: dealing with HashMaps instead of beans
> >
> > > I've encountered 2 jsp apps recently that are passing data around in
> > > HashMaps instead of java classes with getters and setters.  Without
> > > re-writing everything, I'm trying to use struts to re-write the
display
> > > and controller code of these apps, but I haven't found a good way to
> > > deal with these non-bean HashMaps.  I really want to avoid changing
all
> > > the model code that deals with HashMaps, but I'd like to use the
> > > bean-oriented taglibs that struts offers.
> > >
> > > Here's an example.  The model api provides a getProducts method, which
> > > returns a List of HashMaps that contain product-related keys
(productID,
> > > productName, productDescription, ...).  Ideally, I could do something
> > > like this:
> > >
> > > <logic:iterate id="product" name="products">
> > > productID is <bean:write name="product" property="productID"/>
> > > productName is <bean:write name="product" property="productName"/>
> > > productDescription is <bean:write name="product"
> > > property="productDescription"/>
> > > </logic:iterate>
> > >
> > > So, is there some trick or workaround to get HashMaps to work in this
> > > and other cases where beans are expected?  I've seen previous threads
> > > that demonstrate how individual map entries can be accessed as valid
> > > beans, but that's not the issue here.
> > >
> > > Thanks,
> > >
> > > paul
> > >
> > >
> > >
>
>


Mime
View raw message