hi,

Yes, i was referring to copyProperties().

The problem really gets complex if you have nested objects.
and i doubt if there is any readymade solution to the problem you are
facing. but with very little effrots you can do this

You can make one and for all. Doesn't seem to be a tough job althought bit
lengthy :-)

Ok, allow me to get my hands dirty!! and I am not sure if this works with
collections as you may want. You ca try with collections yourself.

Say you have something like

class A (with corresponding gettter and setter)
{
        private B b;
        private String str;
}

class B (with corresponding gettter and setter)
{
        private String str;
}

All you need to do is

A a = new A();
a.setStr("navjot");
B b = new B();
b.setStr("singh");
a.setB(b);

Map m = new HashMap();
Then call BEanUtils.copyProperties(m,a);

you will get a map filled with key-value pairs
str=navjot
b.str=singh

pass this to some function like.

String getQueryStirng(Map m)
{
        Iterator nvPairs = m.keySet().iterator();
        StringBuffer nvString = new StringBuffer("");
        String key;
        while(nvPairs.hasNext())
        {
                key = (String) nvPairs.next();
                nvString.append(key + "=");
                nvString.append(this.getString(key) + "&");
        }
        String nv = nvString.toString();
        if(m.keySet().size() != 0)
        {
                return nv.substring(0,nv.lastIndexOf("&"));
        }
        return nv;
}

My this function may not be efficient and does the job you want.

and HURRAY!! you will get QueryString like
str=navjot&b.str=singh

hope this helps
Navjot Singh

******************
Wife sleeping in the middle of night suddenly wakes up and shout. "Quick! My
husband is back". Man get up and jumps out of window. Then realizes "SHIT! I
AM the husband."
******************


>-----Original Message-----
>From: Patrick Cheng [mailto:[EMAIL PROTECTED]
>Sent: Monday, January 05, 2004 12:05 PM
>To: Struts Users Mailing List
>Subject: RE: Querystring builder
>
>
>Hi Navjot,
>I have been working with the BeanUtils things on this problem.
>Are you referring to the 'describe' and 'populate' methods? That's what
>I've been working on.
>I am looking for yet a simpler way to do this. I should say, I wonder if
>there's an easier way to do this.
>Let me explain a bit on the situation.
>Multipage form. The form bean contains other value objects, and these
>value objects have Collection properties, pointing to another set of
>Value Objects.
>
>That is, in my original formbean:
>   public MyEJBValueObject getXXX(){...}
>   public void setXXXs(MyEJBValueObject e){...}
>In the MyEJBValueObject.java, I have:
>   public Collection getYYYs(){...}
>   public void setYYYs(Collecton c){...}
>And the collection YYY actually is a arraylist of AnotherEJBValueObject
>
>With this kind of structure, it's quite tedious to build the
>QueryString,
>Is that right? I suppose I have to iterate thru the Map described by
>BeanUtils and go into further levels, and describe again.
>The worst part is, I don't want to build the 'Form elements' myself.
>That is,
>I have to come up with indexed/mapped/mixed name, like,
>    SALES.ITEMS[2].DISCOUNT['MONTHLYSPECIAL'].DISCOUNTRATE
>Do I have to do that manually?
>
>Thanks.
>Patrick.
>
>-----Original Message-----
>From: Navjot Singh [mailto:[EMAIL PROTECTED]
>Sent: Monday, January 05, 2004 2:03 PM
>To: Struts Users Mailing List
>Subject: RE: Querystring builder
>
>
>that should be easy.
>
>BeanUtils gives you the way to populate a MAP object from a Bean. Now al
>you need to do is iterate over keys, form a querystring with each
>name-value pair separated by &.
>
>HTH
>Navjot SIngh
>
>
>>-----Original Message-----
>>From: Patrick Cheng [mailto:[EMAIL PROTECTED]
>>Sent: Monday, January 05, 2004 11:19 AM
>>To: Struts Users Mailing List
>>Subject: RE: Querystring builder
>>
>>
>>What I wanted to do is, at some point during the user is completing a
>>form,(multipage)
>>He can save the form.  Instead of serializing the bean and saving Blob
>>in oracle, I am trying to put things in a QueryString and save the
>>string into oracle.
>>And I want to populate that QueryString into a formbean when the user
>>resumes.
>>
>>Any tools?
>>
>>Thanks a lot.
>>Patrick.
>>
>>-----Original Message-----
>>From: James Mitchell [mailto:[EMAIL PROTECTED]
>>Sent: Monday, January 05, 2004 12:14 PM
>>To: Struts Users Mailing List
>>Subject: Re: Querystring builder
>>
>>
>>On Mon, 5 Jan 2004, Patrick Cheng wrote:
>>
>>> Hi All,
>>>
>>> I have been trying to find helper class to build QueryString from
>>> javabean. Does anyone know of any tool like this?
>>
>>What are you wanting to do?  Add parameters from your bean?
>>
>>>
>>> Thanks,
>>> Patrick.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>>--
>>James Mitchell
>>Software Developer / Struts Evangelist http://www.struts-atlanta.org
>>
>>
>>---------------------------------------------------------------------
>>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]
>
>


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

Reply via email to