Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

To: John Carnell, Re: Method Overrides

 
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

The timing of your appearance here could not be better for me.

Just yesterday I learned that I could override struts method ActionForm.reset(ActionMapping mapping, HttpServletRequest request) to smoothly resolve a problem, as that method does not do anything.

My question: What other struts methods would be safe to override, or perhaps add to by calling super.method() and follow with my own code?

Thank You in Advance for Your Help,

Lou
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lou Pe:
Just yesterday I learned that I could override struts method ActionForm.reset(ActionMapping mapping, HttpServletRequest request) to smoothly resolve a problem, as that method does not do anything.


Hmm. What are you now doing in your reset() method?
Besides, usually you can override a method that "does something" and just call super.theMethod() from your overriding method.
[ July 27, 2004: Message edited by: Lasse Koskela ]
 
Sheriff
Posts: 17652
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lou Pe:
I learned that I could override struts method ActionForm.reset(ActionMapping mapping, HttpServletRequest request) to smoothly resolve a problem, as that method does not do anything.

My question: What other struts methods would be safe to override, or perhaps add to by calling super.method() and follow with my own code?



The Struts framework defines a certain sequence of calls to overridable methods, one of which is reset(). The reset() method has a specific purpose (see the JavaDocs) and even though the default implementation does nothing, this does not mean that you have carte blanc to replace it with any code you want. Your actual implementation of reset() should fit in with its purpose within the Struts framework. The same thing is true for all the other non-final overridable methods of the base framework classes.
 
Author
Posts: 93
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lou,

The reset() method is not just there to put code in. It was originally put into place to allow a developer to initialize attributes on an ActionForm before it is populated with data from the form being submitted.

To be lazy and steal some material from my book:

"The reset() method was originally implemented to allow developers to deal with one of the more annoying HTM form controls: checkboxes. When an HTML form is submitted with unchecked checkboxes, no data values are submitted for the checkbox in the HTTP request.

Thus, if an ActionForm is sitting in the user's session and the user changes a checkbox for the ActionForm from true to false, the ActionForm class will not get submitted. Remember, the HTML "input" tag does not send a value of false on an unchecked checkbox.

The reset() method can be used to initialize a form bean property to a pre-determined valu. In the case of a form bean property that represents a checkbox tyhe reset() method can be used to set the property values aways to false."

I have used the reset() method to pre-populate a form with data. Some would disagree with me on this (and they have very valid points), but you just can't put code in the reset() method without understanding how it fits in the overall of the Struts call.

Sorry for the long-winded explanation. I hope that answers your query.

Thanks,
John
 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

That doesn't exactly answer my question, but reaffirms what I have done.

Similar to your checkbox, I used javascript to disable one text entry on a form if another contains any non-space characters.

The problem this caused was when the user submits the form, reverses the text entries and submits again, the text that changed from non-space to empty was not sent - hence the data persisted in my bean. The resolution was to override reset and if the property is not part of the request I know that I can set my bean variable to "".

Now back to my original question: What other struts methods would be safe to override, or perhaps add to by calling super.method() and follow with my own code?

Thanks,

Lou
 
John Carnell
Author
Posts: 93
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lou,

I am not sure what you are trying to accomplish with your "overridden" method.

There are basically three basic places you can plug-in "logic" by overriding a method.

1. The ActionForm.reset() method. Which I kind of covered.
2. The ActionForm.validate() method which is used to submit form data
held within the ActionForm.
3. The Action.execute() method which invokes the business logic used to
process a user's request.

Could you give me a specific example of what you are looking to do? My book promotion will be ending soon, but you are always welcome to email my directly.

Thanks,
John
 
I brought this back from the farm where they grow the tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic