struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jerry Jalenak" <Jerry.Jale...@LABONE.com>
Subject RE: [OT - MethodUtils] How to invoke method from DynaActionForm
Date Thu, 24 Oct 2002 16:32:13 GMT
Craig,

Thanks for the reply.  After I had sent the post I figured out that I was
trying to make this a lot harder than it is.  Ended up using the 'get'
method for DynaActionForm....  here's the whole method:

	public static void populateMap(HashMap hm, DynaActionForm daf)
		throws Exception
	{
		try
		{
			Map map = BeanUtils.describe(daf);
			Iterator mapIterator = map.entrySet().iterator();
		
			while(mapIterator.hasNext())
			{
				Map.Entry me = (Map.Entry)
mapIterator.next();
				hm.put((String) me.getKey(),
daf.get((String) me.getKey()));
			}
		}
		catch(Exception e)
		{}
	}

Thanks again!

Jerry

> -----Original Message-----
> From: Craig R. McClanahan [mailto:craigmcc@apache.org]
> Sent: Thursday, October 24, 2002 11:28 AM
> To: Struts Users Mailing List
> Subject: Re: [OT - MethodUtils] How to invoke method from 
> DynaActionForm
> 
> 
> 
> 
> On Thu, 24 Oct 2002, Jerry Jalenak wrote:
> 
> > Date: Thu, 24 Oct 2002 08:58:06 -0500
> > From: Jerry Jalenak <Jerry.Jalenak@LABONE.com>
> > Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> > To: "'struts-user@jakarta.apache.org'" 
> <struts-user@jakarta.apache.org>
> > Subject: [OT - MethodUtils] How to invoke method from DynaActionForm
> >
> > I know that BeanUtils.populate will populate a JavaBean 
> with values from a
> > HashMap provided the property name match.  Does anyone know 
> of method that
> > will go the other direction (i.e. JavaBean to HashMap)?
> 
> You might try PropertyUtils.describe().  It and all the other stuff in
> beanutils is documented at:
> 
>   http://jakarta.apache.org/commons/beanutils/api/
> 
> Note -- for general purpose Map->Bean property copying, I'd 
> suggest using
> BeanUtils.copyProperties(), which was recently added, instead of
> BeanUtils.populate().  The reason for this is that populate() was
> specifically designed to support the way Struts copies 
> properties from an
> HTTP request, so it does some pretty funky things on indexed 
> properties --
> the copyProperties() method, on the other hand, will behave 
> the way you
> expect.
> 
> If you don't need type conversions, using 
> PropertyUtils.copyProperties()
> instead will run a bunch faster.
> 
> >  I have a need to
> > grab all of the properties from a DynaActionBean and 
> populate a HashMap.  I
> > can get a Map of all of the properties from the 
> DynaActionForm, generate
> > 'get' method names, and I think I can use 
> MethodUtils.invokeMethod to call
> > the getter.  The problem is, with DynaActionForms, there 
> really isn't a
> > 'getter' - what I get is a 'NoSuchMethodException'.  Does 
> anyone know how I
> > can get around this?
> >
> 
> DynaActionForm beans offer you two ways to get property values out:
> 
> * Since they implement DynaBean, you can call the get() method:
> 
>   String address = (String) dynabean.get("address");
> 
> * Nearly all of the BeanUtils and PropertyUtils methods know how to
>   deal with either DynaBeans or standard JavaBeans:
> 
>   String address =
>     (String) PropertyUtils.getSimpleProperty(dynabean, "address");
> 
> 
> > TIA,
> >
> 
> Craig
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 

This transmission (and any information attached to it) may be confidential and is intended
solely for the use of the individual or entity to which it is addressed. If you are not the
intended recipient or the person responsible for delivering the transmission to the intended
recipient, be advised that you have received this transmission in error and that any use,
dissemination, forwarding, printing, or copying of this information is strictly prohibited.
If you have received this transmission in error, please immediately notify LabOne at (800)388-4675.



--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message