Hi,

I have implemented your code below for dynamic forms and it works a
treat, I might even say it is a little more convenient than the actual
DynaActionForm as you don't have to declare any form properties in the
struts-config file.

Although I do have one question for you.  Have you managed to implement
this using the struts validator?  I would be quite keen on using the
struts validator for dynamic forms/properties with this particular
workaround.  

Regards,
Adrian Cunningham

PS.....Out of curiousity what do you think of the workaround I came up
with?



"Bhattad, Nilesh " <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
> I'm also facing the same problem of Dynamic properties with Struts 
> 1.0/1.1 As a workaround, I created my own classes DynaForm and 
> DynaFormClass
> 
> I'm attaching a pseudo code of DynaForm and DynaFormClass
> 
> 
> 
> ////////////////////////
> // A Form class which is common for all JSP pages 
> //////////////////////// public class DynaForm extends DynaActionForm
> {
>     DynaFormClass formClass = new DynaFormClass();
>       
>     public Object get(String name) 
>     {
>         Object value = dynaValues.get(name);
>         return (value);
>     }
> 
>     public void set(String name, Object value) 
>     {
>         dynaValues.put(name, value);
>     }
>     
>     public DynaClass getDynaClass() 
>     {
>         return (this.formClass);
>     }
> }
> ////////////////////////
> 
> 
> ////////////////////////
> // As DynaActionForm needs a descriptor object attached to it, // this

> class implements DynaClass interface and always returns Object // as a

> property. ////////////////////////
> public class DynaFormClass implements DynaClass
> {
>       private static Class cls;
>       private static DynaProperty property;
>       
>       static
>       {
>               cls = new Object().getClass();
>               property = new DynaProperty(null, cls);
>       }
>       
>       public String getName()
>       {
>               return null;
>       }
>       
>       public DynaProperty getDynaProperty(String name)
>       {
>               return new DynaProperty(null, cls);
>       }
>       
>       public DynaProperty[] getDynaProperties()
>       {
>               return null;
>       }
>       
>       public DynaBean newInstance()
>               throws IllegalAccessException, InstantiationException
>       {
>               return new DynaForm();
>       }
> }
> 
> 
> //////////////////////
> // struts-config.xml
> //////////////////////
> <form-beans>
>     <form-bean  name="test"
>                 type="com.onebeacon.struts.action.DynaForm">
>     </form-bean>
> </form-beans>
> 
> <action    path="/test"
>            type="com.onebeacon.struts.action.ActionHandler"
>            name="test"
>            scope="request">
>        
>       <forward name="index"              path="/index.jsp"/>
>       <forward name="home"               path="/logon.jsp"/>
> </action>
> 
> 
> Please let me know if someone has a better solution for using Dynamic 
> properties.
> 
> Thanks
> Nilesh
> 
> 
> -----Original Message-----
> From: Daniel Hinz [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 24, 2002 9:44 AM
> To: Struts Users Mailing List
> Subject: Dynamic Properties
> 
> Hi,
> 
> i posted a feature request on struts-dev on friday, which i'd like to 
> bring to this forum for dicsussion. Although this has already been 
> discussed in some threads, a satifactory conclusion has not been 
> reached (at least in my opinion). So here it goes:
> 
> A) Use Cases:
> 1) Develop a generic RDMBS Browser using Struts.
> 2) Develop a WebInterface for arbitrary XML editing.
> 
> B) Problems in Struts 1.0 and 1.1:
> For each property A the corresonding setA / getA methods are invoked 
> upon read/write. There's nothing wrong with that. However i must 
> deploy form fields that are unknown to me at compile-time. Thus i 
> cannot write a Bean with the appropriate methods.
> 
> C) Request for extending org.apache.struts.action.ActionForm:
> A simple solution would be to introduce methods with the following
> signature:
> public void setProperty(String propertyName, Object propertyValue) 
> public Object getProperty(String propertyName)
> 
> D) Workaround:
> None known to me. There's a class called DynaActionForm which allows 
> you to add a dynamic number of fields *in the struts-config.xml file*.

> This is not feasible since the properties are unknown at Servlet 
> Initialization time.
> 
> I'm quite new to Struts so please forgive me if i missed something 
> blatantly obvious.
> 
> Regards,
> 
> Daniel Hinz
> 
> --
> Daniel Hinz
> Software Engineer
> [EMAIL PROTECTED]
> 
> 
> --
> To unsubscribe, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 


--

This e-mail is confidential and is intended for the named recipient only. If
you receive it in error please destroy the message and all copies. Kainos
Software Ltd. does not accept liability for damage sustained as a result of
malicious software (e.g. viruses). Kainos does not accept liability for, or
permit; the creation of contracts on its behalf by e-mail, the publication of
any defamatory statement by its employees by e-mail, or changes subsequently
made to the original message. The Company's registered office is located at
4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland, Tel +44 28 9057 1100.

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

Reply via email to