Nice..

Thats quite slick..

Also have you tried to submit the form yet? and print out its contents? I'd be interested to know..

Cheers Mark

On Saturday, August 23, 2003, at 04:29 PM, R Balaji wrote:

wow, thanks mark.

i managed to make the things working like this ,,,

String className = viewBean.getDynaClass().getName();
FormPropertyConfig propConfig = null;
Enumeration keys = viewData.keys();
while(keys.hasMoreElements())
{
String key=(String)keys.nextElement();
String value = (String)viewData.getProperty(key);
propConfig = new FormPropertyConfig(key,"java.lang.String",value);
config.addFormPropertyConfig(propConfig);
} DynaActionFormClass beanClass= DynaActionFormClass.createDynaActionFormClass(config);
viewBean = (DynaValidatorForm) beanClass.newInstance(); BeanUtils.populate(viewBean, viewData);


it is working fine now ....

Regards,
b


Mark Lowe wrote:


Okay

The code for creating a dynaBean etc is in the archieves when i messing around with dynaResultSet or whatever it was called.

Then try creating a form property form the key-value pairs..BeanUtils is just useful short-hand. But thats irrelevant now i know what you're trying to do.

You'll have an easier time by nesting beans as your form-property, and then i guess you beans will have to have a map or list style interface to pull generate your form.

Please any snippets are demonstration of concept, I could be very wrong.. but something like this. Using indexed properties should help you stop having to define dynaBeans on the fly, which last time i played with doing that things got very slow.

<form-property name="resource" type="java.util.ArrayList" />
...
public class ManagedResourceBean {
        private ArrayLIst list;
        public ArrayList getList() {
        return list;
    }

    getValue(int index) {
        return list.get(index).toString();
    }

    setValue(String str) {
        list.add(str);
    }
        }


..


ManagedResourceBean bean = new ManagedResourceBean();

iterator it = myResourcesFromMyModel.getResouces();

while(it.hasNext()) {
    bean.setValue(it.next());   }

theForm.set("resource",bean.getList());
..

<logic:iterate id="item" name="myForm" property="resource">
    <html:text name="item" property="value[index]" />
</logic:iterate>

..

Some of the details are certainly wrong but I think the concept is okay.

Cheers Mark


On Saturday, August 23, 2003, at 12:22 PM, R Balaji wrote:


Hi Mark,

Thanks for your mail.
I tried your, our first suggestion, but the BeanUtils.populate(), wont go well with this dynamic properties. It throws


java.lang.NullPointerException at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:926 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808) at com.adventnet.nms.webclient.topo.details.ObjectDetailsAction.populate Vi ewBean(ObjectDetailsAction.java:139)

Actually, i am trying to display the properties of different ManagedResources. The will have different properties ( some may have 10, and others may have 30 properties, including few in this 10 ) ... so i can not pre-determine the properties, and specify them in the <form-property> tag.
Only while fetching and populating the bean , i will get to know the list of properties to be displayed in the UI. This stops me from modeling a bean for the view data.


Hope i m clear ...

I am jst trying your second approach .. do you have any code snippet for that ...

Thanks & regards,
R Balaji


Mark Lowe wrote:


You cant dynamically add properties to DynaActionForms. I'm not sure why you've a problem with just adding the fields to you form bean in struts config. I've demonstrated how to literally do what you want, but you'd have to specify the properties you want in you jsp anyway. But here goes....

You could create a new form bean copy the properties across from you old one and then add some new stuff..

DynaActionForm oldForm = (DynaActionForm) form;

//get the map out and mess with this and life should be simpler that using the dynaBean
Map oldFormMap = oldForm.getMap();


oldFormMap.put("statusChangeTime","A new Time");

DynaActionForm newForm = new DynaActionForm();

BeanUtils.populate(newForm, oldFormMap);

If this doesn't work you can try constructing all you dyna properties, having a DynaProperty[] array and then use the dynaBean constructer that takes a properties array.

Cheers Mark


On Saturday, August 23, 2003, at 04:42 AM, R Balaji wrote:


Dear All,
I have an application which returns a varity of properties, which can not be decided at design time. I would like to populate the Business data into a dynaValidatorForm and display them.


In this case, it is not possible to specify all the properties as <form-property>. If i set properties, without specifying them in the struts-config.xml, i am getting exception as mentioned below.

java.lang.IllegalArgumentException: Invalid property name 'statusChangeTime'
at org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionF or m. java:598)
at org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:412 )
at com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.popul at eV iewBean(ObjectDetailsHandler.java:63)
at com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.fetch Ob je ctDetails(ObjectDetailsHandler.java:49)
at com.adventnet.nms.webclient.topo.details.ObjectDetailsAction.execut e( Ob jectDetailsAction.java:54)


Please help me , in this regards,

Thanks in Advance.
With Regards,
R Balaji


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




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




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



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



Reply via email to