commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anil Mandava <amand...@altoweb.com>
Subject (Beanutils) Mapped properties - creating beans on the fly - spec ifying class name in property ???
Date Wed, 12 Dec 2001 22:55:24 GMT
Hi,
Goal:
I am trying to create a 'generic' form bean for use with my Struts actions.
The form bean will make use of the Beanutils' good features such as mapped
properties and nested properties.

To achieve that, I am finding a need for Beanutils to dynamically create
beans for nested-mapped properties.
e.g., My generic form bean has one mapped property - "value" with getter as 
	"Object getValue(String key)".
In my struts/jsp form, I specify a field with property "value(xyz).abc",
when that form is sumbitted, it translates into following call:
<genericbean>.getValue("xyz").setAbc(...).

Problem is that getValue("xyz") returns null by default, Beanutils stops
there.

If it were possible to specify my bean class name, say
"value(xyz){MyXyzBean}.abc"
then perhaps Beanutils could
1) do <genericbean>.getValue("xyz")
2) if it returns null, check for class name in {} delimters
3)********* do Class.forName("MyXyzBean").newInstance()
4) put that back into <genericbean>.setValue("xyz", xyzbean)
5) xyzbean.setAbc(...)

I was wondering if anyone else has come across a need like that, or even
better has some code somewhere to do that.
If not, I will attempt doing it (and submit a patch).

If there is anything wrong in the whole approach of specifying a class name
as part of property, please let me know.

Thanks in advance,
Anil

-----Original Message-----
From: robert burrell donkin [mailto:robertdonkin@mac.com]
Sent: Wednesday, December 12, 2001 10:51 AM
To: Jakarta Commons Developers List
Cc: Velocity Developers List
Subject: Re: (Beanutils)[SUBMIT] MethodUtils


On Wednesday, December 12, 2001, at 08:18 AM, Christoph Reck wrote:

> robert burrell donkin wrote:
>> you'll probably wonder why the method is called invokeExactMethod (rather
>> than invokeMethod, say). that's because i plan to add another method that
>> searches for a correctly named method with compatible parameters (rather
>> than exact matching) but i though that it'd be better to submit the
>> patches required to fix Donnie's problem (and then add more functionality
>> later).
>
> Please check the Velocity method-finding introspection code, it probably
> does what you need, and could become part of the commons. Recently it
> was upgraded to find interface public methods on private classes...

hi Christoph

(beanutils already had some private code that did just that. the patch 
moved that code into a separate class, made it public and added some 
convenience wrappers.)

i have taken a quick look (at the velocity introspection code) and there 
are certainly a number of useful utility methods which might make good 
additions to beanutils. want to volunteer to mine velocity?

maybe it'd make some sense to try to consolidate - as far as possible - 
the general reflection code into beanutils. i know that gier supplied some 
of the code so maybe that was his original plan...

- robert


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

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


Mime
View raw message