To "clone" a DynaValidatorForm perhaps something like this will work:

LazyDynaBean obj = new LazyDynaBean();  // create a lazy dyna bean
BeanUtils.copyProperties(obj, dyForm);  // save your form properties
session.setAttribute("saved.obj", obj);

...

LazyDynaBean obj = session.getAttribute("saved.obj");
BeanUtils.copyProperties(dyForm, obj);  // restore your form properties


-----Original Message-----
From: Christopher Schultz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 31 October 2006 11:33 AM
To: Struts Users Mailing List
Subject: Re: Rolling back form changes

All,

> Now I just need to figure out how to copy one of these things. It
> looks like "getMap" might be my best option. Any reason why this
> might be a bad idea? 'cause this class is not clonable, and it
> doesn't have a copy constructor, so this looks like the only
> possibility.

To answer my own question, cloning a DynaActionForm (of which
DynaValidatorForm is a subclass), the following unholy incantation is
necessary:

        ModuleConfig mc = mapping.getModuleConfig();
        FormBeanConfig fbc = mc.findFormBeanConfig(mapping.getName());

        DynaActionForm clonedForm
            = (DynaActionForm)fbc.createActionForm(super.getServlet());

        for(Iterator i=form.getMap().entrySet().iterator(); i.hasNext();
)
        {
            Map.Entry entry = (Map.Entry)i.next();

            clonedForm.set((String)entry.getKey(), entry.getValue());
        }

I tried simply instantiating a new DynaValidatorForm object and then
running the loop shown above. Apparently, that doesn't initialize the
form bean properly, and you get a NPE when calling set(). Calling
"initialize" or "reset" on the bean also doesn't work: initialize()
actually bombs with the same NPE as set() does, and reset() just doesn't
do the trick.

I'd love to hear any other ideas, but for now, this technique works and
I couldn't make it work another way.

-chris

**********************************************************************
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**********************************************************************

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

Reply via email to