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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to