aspose file tools*
The moose likes Struts and the fly likes calling reset() method explicitly -- good or bad Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "calling reset() method explicitly -- good or bad" Watch "calling reset() method explicitly -- good or bad" New topic
Author

calling reset() method explicitly -- good or bad

Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Hi Ranchers,

We have a scenario wherein after submitting the form an update operation takes place in the database and the user is displayed with the same page.

But this time, the form values have to be reset and displayed afresh so that the user can enter further values and add it to the database.

Looking at this consequence, the reset() method in the ActionForm has to be called explicitly as it is called after the form is submitted and before the bean is populated with the request parameter values. That is very fine. But what we need is the form has to be reset during the page loading the next time.

Can we call the reset method in the Form bean and invoke it in the Action class once our database updating operation is done? I think it is somehow not a better way as its like life cycle method which is supposed to be handled by the Struts framework.

Other alternative is to mimic the reset() method in a separate method and invoke it in the Action class which could clear the required fields.

What is the best way out of these two? is there any other better way to handle this scenario?

Thanks in advance!
[ May 14, 2008: Message edited by: Raghavan Muthu ]

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Raghavan Muthu,

I think you can effectly handle your situation at client side using javascript.


Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Hi Srinivasan,

Thank you. Yes that is a good suggestion. We can clear the fields using JavaScript when the form is getting loaded.

But how about the reset() method in Server side? Is it advisable or not at all? Any idea? Just waiting to hear on that part.
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Raghavan,

As you felt, calling life-cycle methods explicitly is not a good idea.

What I feel is "Our code should be understandable to all."

Keep it simple. be

Think about code reviewers also !!!
[ May 16, 2008: Message edited by: Srinivasan thoyyeti ]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

That's great. Thanks Srinivasan!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling reset() method explicitly -- good or bad