Hi all,

I 'm trying to use the last great struts 1.1 feature, aka dynabeans, for my
application. I wasn't able to use it as is because DynaActionForm supposes
the form bean properties (and so the form fields) are known at configuration
time.

In my case, the form bean properties are only known at runtime and I want
the same form bean to handle totally different forms. I don't want the form
developer to have to declare a new form bean in struts-config for each form.
The 'business logic' I'm working upon is able to provide me with an object
(let's name its class FormProperties) describing both the form properties
and their initial values. The form page (ie jsp url) to use is also
retrieved from the FormProperties object.

So, I wrote a DynaActionForm subclass (let's say RuntimeDynaActionForm)
which embeds the FormProperties object which is similar to an hashtable,
except it also carries out property type information and is able to handle
indexed properties by itself. Notice the FormProperties instance may change
at every request depending on which form is selected by the user. A specific
action is in charge of adding the FormProperties object in the http session
and the DynaActionFormClass bound to the RuntimeDynaActionForm bean is
redefined at each request by building the right form bean config from this
http session attribute. This takes place in
RuntimeDynaActionForm.reset(mapping, request).

And you know what, it works ! It has to be enhanced like, for instance, form
description object in the http session prevents concurrent form handling. My
idea is very to reuse the maximum of struts (like validation, taglib, ...)
starting from a slight different assumption.

Now, the bug I think I found out. I had to change a little
DynaActionFormClass. Apparently, it intends to double check the dynabean
class is a sub-class of DynaActionForm when creating a new bean but does the
opposite. Here is the patch I'm proposing.


Index: DynaActionFormClass.java
===================================================================
RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/action/DynaAction
FormClass.java,v
retrieving revision 1.2
diff -r1.2 DynaActionFormClass.java
326c326
<         if (!beanClass.isAssignableFrom(DynaActionForm.class)) {
---
>         if (!DynaActionForm.class.isAssignableFrom(beanClass)) {


Moreover, since my DynaActionFormClass object changes at every request, I
have to clear all the already-registered DynaActionFormClass by calling
DynaActionFormClass.clear() and create a new one by calling
DynaActionFormClass.createDynaActionFormClass(config) to assign it to
DynaActionForm dynaClass protected member. This is the only way I can
replace the DynaActionFormClass associated with my special dynabean.

It would be nice to have a static
DynaActionFormClass.replaceDynaActionFormClass(config). I can code and
submit it if you think it is meaningful.

Perhaps, there was another way to do what i'm trying. Like modifying
struts-config at runtime to add new FormBeanConfigs. But, I understood the
application config is frozen... Let me know.

Cheers

Laurent Farcy
[R&D]
Akazi Technologies
6A, chemin des Prés
38240 Meylan - France

<http://www.akazi.com/>
tel +33 (0)4 56 38 2000
fax +33 (0)4 56 38 2001



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to