question regarding DynaActionForm.reset()
The API for ActionForm.reset() says it will, Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet. Why then does the default reset() method for DynaActionForm do nothing? DynaActionForm knows about its own dynamic properties, it would be easy enough to clear() the map. Note I'm not complaining, the resulting behavior is actually what I think I want to have happen, I'm just trying to figure out why it's designed this way...? - donald - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question regarding DynaActionForm.reset()
On Mon, 31 Mar 2003, Donald Ball wrote: Date: Mon, 31 Mar 2003 13:39:33 -0500 From: Donald Ball [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: question regarding DynaActionForm.reset() The API for ActionForm.reset() says it will, Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet. Why then does the default reset() method for DynaActionForm do nothing? DynaActionForm knows about its own dynamic properties, it would be easy enough to clear() the map. Note I'm not complaining, the resulting behavior is actually what I think I want to have happen, I'm just trying to figure out why it's designed this way...? Originally, the reset() method actually did mess with the map, but this behavior was inconsistent with the do-nothing behavior of reset() in the standard ActionForm class. The bug report related to this was: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14669 As a result, we removed the previous behavior of reset(), in version 1.7 of DynaActionForm just before 1.1-beta3 was released. - donald Craig - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question regarding DynaActionForm.reset()
Hi, Two questions related to this issue: 1) Does this mean that the following statement in Chuck Cavanaugh's Programming Jakarta Struts (O'Reilly) is wrong?: Unlike with the ActionForm Class, where the default behavior for reset() does nothing, the reset() method in the DynaActionForm class resets all the properties back to their initial values. 2) Does DynaValidatorForm.reset() also do nothing? According to the Javadoc, it should Reset all properties to their default values, however, when I run the following code snippet in my Action class (the variable form is the ActionForm object that is given to the method): DynaValidatorForm dynaForm = (DynaValidatorForm) form; String firstNameBefore = (String) dynaForm.get(firstName); // SRM debug: System.out.println(initRequestForm(): resetting form values.); dynaForm.reset(mapping, request); String firstNameAfter = (String) dynaForm.get(firstName); // SRM debug: System.out.println(Value before reset: + firstNameBefore); System.out.println(Value after reset: + firstNameAfter); it prints out identical values for firstNameBefore and firstNameAfter, even if I have set a default value using the initial attribute in struts-config.xml. Thanks, Scott Moore [EMAIL PROTECTED] -Original Message- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED] Sent: Monday, March 31, 2003 2:52 PM To: Struts Users Mailing List Subject: Re: question regarding DynaActionForm.reset() On Mon, 31 Mar 2003, Donald Ball wrote: Date: Mon, 31 Mar 2003 13:39:33 -0500 From: Donald Ball [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: question regarding DynaActionForm.reset() The API for ActionForm.reset() says it will, Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet. Why then does the default reset() method for DynaActionForm do nothing? DynaActionForm knows about its own dynamic properties, it would be easy enough to clear() the map. Note I'm not complaining, the resulting behavior is actually what I think I want to have happen, I'm just trying to figure out why it's designed this way...? Originally, the reset() method actually did mess with the map, but this behavior was inconsistent with the do-nothing behavior of reset() in the standard ActionForm class. The bug report related to this was: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14669 As a result, we removed the previous behavior of reset(), in version 1.7 of DynaActionForm just before 1.1-beta3 was released. - donald Craig - 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]
Re: question regarding DynaActionForm.reset()
Craig R. McClanahan wrote: The API for ActionForm.reset() says it will, Reset all bean properties to their default state. This method is called before the properties are repopulated by the controller servlet. Why then does the default reset() method for DynaActionForm do nothing? DynaActionForm knows about its own dynamic properties, it would be easy enough to clear() the map. Originally, the reset() method actually did mess with the map, but this behavior was inconsistent with the do-nothing behavior of reset() in the standard ActionForm class. The bug report related to this was: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14669 As a result, we removed the previous behavior of reset(), in version 1.7 of DynaActionForm just before 1.1-beta3 was released. Thanks, Craig, always willing and ready to step in with a clear and helpful answer. Unfortunately, I'm still a little bit confused (and I suspect I'm not entirely alone in that regard). 1. DynaActionForm doesn't clear its bean values on reset() because ActionForm does not - but DynaActionForm is a concrete implementation, while ActionForm is abstract, practically speaking if not actually in the code. You could just as easiy argue that ActionForm does clear its values on reset() - it just has none to clear! 2. I guess more to the point, why do you call reset() before manipulating the bean anyway? isn't it better to explicitly keep the old values around before setting any new ones based on the incoming request? Finally, any suggestions you have re: my design pattern question on deriving form beans from underlying model object would be very much appreciated if you have a minute. Otherwise I'll keep playing around. - donald - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question regarding DynaActionForm.reset()
Moore, Scott R. wrote: 1) Does this mean that the following statement in Chuck Cavanaugh's Programming Jakarta Struts (O'Reilly) is wrong?: Unlike with the ActionForm Class, where the default behavior for reset() does nothing, the reset() method in the DynaActionForm class resets all the properties back to their initial values. according to the 1.1rc1 source code, yes, that statement is now wrong. 2) Does DynaValidatorForm.reset() also do nothing? According to the Javadoc, it should Reset all properties to their default values, however, when I run the following code snippet in my Action class (the variable form is the ActionForm object that is given to the method): according to the 1.1rc1 source code, yes, DynaValidatorForm.reset() does not reset its bean values. it _does_ reset the state of the validation, however. glad i'm not the only one slightly confused here. perhaps this api might be refactored for struts 1.2? - donald - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question regarding DynaActionForm.reset()
Scott wrote: 2) Does DynaValidatorForm.reset() also do nothing? According to the Javadoc, it should Reset all properties to their default values, however, when I run the following code snippet in my Action class (the variable form is the ActionForm object that is given to the method): Anecdotally, yes, DynaValidatorForm.reset() does nothing. You have to implement it in your own form if you want it to do something. public void reset( ActionMapping mapping, HttpServletRequest request ) { initialize(mapping); } It's documented on DynaValidatorForm's parent, DynaActionForm: http://jakarta.apache.org/struts/api/org/apache/struts/action/DynaActionForm .html -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management
RE: question regarding DynaActionForm.reset()
Donald wrote: why do you call reset() before manipulating the bean anyway? isn't it better to explicitly keep the old values around before setting any new ones based on the incoming request? Without reset, you'd never be able to 'un-check' an HTML checkbox. -- Wendy
Re: question regarding DynaActionForm.reset()
Wendy Smoak wrote: Donald wrote: why do you call reset() before manipulating the bean anyway? isn't it better to explicitly keep the old values around before setting any new ones based on the incoming request? Without reset, you'd never be able to 'un-check' an HTML checkbox. Sure you would - you'd interpret a null request parameter value for the checkbox input as un-checked, just like web programmers have always done...? it's easy to distinguish between the three incoming states: 1. form submitted, checkbox checked - foo=bar 2. form submitted, checkbox unchecked - foo= 3. user entered through something besides the form - no request parameter named foo (btw, if this issue is dead and buried, feel free to point me to an old thread or tell me to shut up. :) ) - donald - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question regarding DynaActionForm.reset()
HTML does not submit a null for an unchecked checkbox. So if you have foo=bar you would have nothign if foo was not checked. If you try it with a GET HTML form you'll see that behavior. -Tim -Original Message- From: Donald Ball [mailto:[EMAIL PROTECTED] Sent: Monday, March 31, 2003 3:56 PM To: Struts Users Mailing List Subject: Re: question regarding DynaActionForm.reset() Wendy Smoak wrote: Donald wrote: why do you call reset() before manipulating the bean anyway? isn't it better to explicitly keep the old values around before setting any new ones based on the incoming request? Without reset, you'd never be able to 'un-check' an HTML checkbox. Sure you would - you'd interpret a null request parameter value for the checkbox input as un-checked, just like web programmers have always done...? it's easy to distinguish between the three incoming states: 1. form submitted, checkbox checked - foo=bar 2. form submitted, checkbox unchecked - foo= 3. user entered through something besides the form - no request parameter named foo (btw, if this issue is dead and buried, feel free to point me to an old thread or tell me to shut up. :) ) - donald - 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]
Re: question regarding DynaActionForm.reset()
Chen, Gin wrote: HTML does not submit a null for an unchecked checkbox. So if you have foo=bar you would have nothign if foo was not checked. If you try it with a GET HTML form you'll see that behavior. you're so right, mea culpa. i can't believe i misremembered about that inanity. i'll crawl back into my cave now. - donald - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question regarding DynaActionForm.reset()
A coworker pointed out a workaround for explicitly resetting a DynaValidatorForm in my Action class, so I thought I'd share it. In the Action class that handles an ActionForm (which is really a DynaValidatorForm configured in struts-config.xml): // form is the ActionForm object passed in to the method DynaValidatorForm dynaForm = (DynaValidatorForm) form; dynaForm.getMap().clear(); This is helpful in situations like mine, where: - The user enters some data in a form, then gets some errors reported by the Validator framework. - The user is shown a form with error messages, and each form field is pre-populated with data they just submitted so they can quickly correct their errors - The user goes elsewhere in your web app, then returns to the form mentioned above, and you do NOT want to pre-populate the form fields with the data they entered before. HTH. Thanks Wendy and Donald for your replies earlier. --Scott [EMAIL PROTECTED] -Original Message- From: Wendy Smoak [mailto:[EMAIL PROTECTED] Sent: Monday, March 31, 2003 3:45 PM To: 'Struts Users Mailing List' Subject: RE: question regarding DynaActionForm.reset() Scott wrote: 2) Does DynaValidatorForm.reset() also do nothing? According to the Javadoc, it should Reset all properties to their default values, however, when I run the following code snippet in my Action class (the variable form is the ActionForm object that is given to the method): Anecdotally, yes, DynaValidatorForm.reset() does nothing. You have to implement it in your own form if you want it to do something. public void reset( ActionMapping mapping, HttpServletRequest request ) { initialize(mapping); } It's documented on DynaValidatorForm's parent, DynaActionForm: http://jakarta.apache.org/struts/api/org/apache/struts/action/DynaActionForm .html -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]