Re: Rolling back form changes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dave, Dave Newton wrote: For a DynaValidatorBean, no such methods exist. http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api/ 'If the origin bean is actually a Map, it is assumed to contain String-valued simple property names as the keys, pointing at the corresponding property values that will be converted (if necessary) and set in the destination bean.' Wow. The documentation was apparently gutted after the 1.6.1 version: 1.7.0:http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api 1.7.1:http://jakarta.apache.org/commons/beanutils/apidocs/ Neither of these sets of javadoc mention this capability. Again, the problem was creating the target bean, not copying the properties. Thanks, though. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFR1AA9CaO5/Lv0PARAsncAJ0cZlz8HGwA5GmYa3E3giuErcWT9ACfUpkR a3CzmfsEbtKBxhyh/afQ4eI= =7gxh -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Rolling back form changes
On 10/31/06, Christopher Schultz [EMAIL PROTECTED] wrote: Again, the problem was creating the target bean, not copying the properties. Thanks, though. How about posting the stack trace / line number that its throwing the NPE on? Also what Struts version are you using? Niall - -chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Rolling back form changes
From: Christopher Schultz [mailto:[EMAIL PROTECTED] Really? BeanUtils.copyProperties seems to indicate that it copies bean properties which are usually defined as strings for which the methods getFoo and setFoo exist. For a DynaValidatorBean, no such methods exist. http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs /api/ 'If the origin bean is actually a Map, it is assumed to contain String-valued simple property names as the keys, pointing at the corresponding property values that will be converted (if necessary) and set in the destination bean.' Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Rolling back form changes
All, I have a multi-page flow and I am using a DynaValidatorForm to store all my form info. At the end of the flow, there's a confirmation page where the user can check out all of the information entered during the previous several pages. They have the opportunity to go back to each page (via a link) and change the data on those pages individually. If a user goes back, changes some text in a text box (for example), and then chooses the CANCEL button, the form is submitted, and the DynaValidatorForm is filled with the changed data. This is non-ideal, as I want the updated data to be discarded (since the user hit CANCEL). The obvious solution is to save a copy of the form bean before such a page is displayed (say, in the session), and then, if the user hits CANCEL, to resurrect that form bean. The question is: how should one bring back that bean? Struts provides the form bean object to each Action, so it's easy to get a reference to it, clone it, and shove it in the session as a backup copy. But, there's no API-happy way to put it back if I want to, is there? It looks like the only option I have is to push that form bean into the session with a known name. Since I know the name of the form, I can just use that, but it means having to hard-code the name of the form into my action. Is there a better way? Is there a way to get the name of the currently active form? Thanks, -chris signature.asc Description: OpenPGP digital signature
RE: Rolling back form changes
From: Christopher Schultz [mailto:[EMAIL PROTECTED] Is there a way to get the name of the currently active form? Is that what ActionMapping's getName() does? Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Rolling back form changes
You might have a look at the html:cancel button. (*Chris*) On 10/30/06, Christopher Schultz [EMAIL PROTECTED] wrote: All, I have a multi-page flow and I am using a DynaValidatorForm to store all my form info. At the end of the flow, there's a confirmation page where the user can check out all of the information entered during the previous several pages. They have the opportunity to go back to each page (via a link) and change the data on those pages individually. If a user goes back, changes some text in a text box (for example), and then chooses the CANCEL button, the form is submitted, and the DynaValidatorForm is filled with the changed data. This is non-ideal, as I want the updated data to be discarded (since the user hit CANCEL). The obvious solution is to save a copy of the form bean before such a page is displayed (say, in the session), and then, if the user hits CANCEL, to resurrect that form bean. The question is: how should one bring back that bean? Struts provides the form bean object to each Action, so it's easy to get a reference to it, clone it, and shove it in the session as a backup copy. But, there's no API-happy way to put it back if I want to, is there? It looks like the only option I have is to push that form bean into the session with a known name. Since I know the name of the form, I can just use that, but it means having to hard-code the name of the form into my action. Is there a better way? Is there a way to get the name of the currently active form? Thanks, -chris
RE: Rolling back form changes
It's been a couple years since I did this, so I apologize for possible inaccuracies. I remember calling a method (something like beanCopy?) that allows cloning and setting a form with a single call. When I searched the API I could not find it, but I noticed DynaActionForm.getMap() that seems to perform a similar function. Bruno -Original Message- From: Christopher Schultz [mailto:[EMAIL PROTECTED] Sent: Monday, October 30, 2006 11:38 AM To: Struts Users Mailing List Subject: Rolling back form changes All, I have a multi-page flow and I am using a DynaValidatorForm to store all my form info. At the end of the flow, there's a confirmation page where the user can check out all of the information entered during the previous several pages. They have the opportunity to go back to each page (via a link) and change the data on those pages individually. If a user goes back, changes some text in a text box (for example), and then chooses the CANCEL button, the form is submitted, and the DynaValidatorForm is filled with the changed data. This is non-ideal, as I want the updated data to be discarded (since the user hit CANCEL). The obvious solution is to save a copy of the form bean before such a page is displayed (say, in the session), and then, if the user hits CANCEL, to resurrect that form bean. The question is: how should one bring back that bean? Struts provides the form bean object to each Action, so it's easy to get a reference to it, clone it, and shove it in the session as a backup copy. But, there's no API-happy way to put it back if I want to, is there? It looks like the only option I have is to push that form bean into the session with a known name. Since I know the name of the form, I can just use that, but it means having to hard-code the name of the form into my action. Is there a better way? Is there a way to get the name of the currently active form? Thanks, -chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Rolling back form changes
Dave- base class ActionConfig has method getName() which acquires name of underlying form bean JavaDoc at http://struts.apache.org/1.2.7/api/org/apache/struts/config/ActionConfig.html#getName() Anyone else? M- This e-mail communication and any attachments may contain confidential and privileged information for the use of the designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its contents - Original Message - From: Dave Newton [EMAIL PROTECTED] To: Struts Users Mailing List user@struts.apache.org Sent: Monday, October 30, 2006 12:47 PM Subject: RE: Rolling back form changes From: Christopher Schultz [mailto:[EMAIL PROTECTED] Is there a way to get the name of the currently active form? Is that what ActionMapping's getName() does? Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Rolling back form changes
Dave, From: Christopher Schultz [mailto:[EMAIL PROTECTED] Is there a way to get the name of the currently active form? Is that what ActionMapping's getName() does? Duh! Thanks. I'm a moron. 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. -chris signature.asc Description: OpenPGP digital signature
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 signature.asc Description: OpenPGP digital signature
RE: Rolling back form changes
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]
Re: Rolling back form changes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Paul, 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); Really? BeanUtils.copyProperties seems to indicate that it copies bean properties which are usually defined as strings for which the methods getFoo and setFoo exist. For a DynaValidatorBean, no such methods exist. It also turns out that creating the target object is the problem, not copying the properties. My simple loop over the bean's property map is sufficient. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFRqPK9CaO5/Lv0PARAst0AJ0VCwfqSjqHOiVmzQbmWVfDRCfPFwCfQ8ON BKt7dzQABmipctTcHfQ5Aoo= =dg/b -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]