Bech on Enterprise Java
Tuesday, July 25, 2006
  Struts 1.2: Why is not the reset, validate or even execute invoked?
Here is another one of those stupid mistakes that can keep you wondering what's going on;

As you probably know, Struts lets you override methods in the ActionForm class. It's quite common to override both the validate(), and reset() method.

It's however very important to notice that there exists two of each ;

public void reset(ActionMapping mapping,
javax.servlet.ServletRequest request)

public void reset(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)


and

public ActionErrors validate(ActionMapping mapping,
javax.servlet.ServletRequest request)

public ActionErrors validate(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)


If you override the wrong method (the ones with the ServletRequest signature, instead of HttpServletRequest), you'll soon notice that you code is not getting executed.

The JavaDoc claims for the generic methods "The default implementation attempts to forward to the HTTP version of this method." What "Attemts" means beats me. In the cases where I've made this mistake uptil now, that "attemt" has not succeeded.

Please note that this fact also applies to the Action class itself. There exists one execute() method for the Generic Servlet Class, and one for the HTTP Servlet.

I'm not sure why the design is like this; I havn't heard of anyone using Struts to SIP Servlets, or any other kinds of servlet other than HTTP.

If you googled for the problem, and found my page; Please let me know and add a comment ! :-)
 
Comments:
yes it helped me .. i was calling reset without using the http version .. thanks for posting it online ... thanks ...
 
i came via google to your page. though I am still dealing with the problem, lets hope the ordeal ends soon!
 
I've also found your page via google. Yes, why these methode with a parameter of type ServletRequest exists ? Nobody'll use it !
 
Post a Comment



<< Home
I hereby promise to blog my thoguhts and views on Enterprise java, design patterns, frameworks and all other things that make life as a software developer interesting.

Name:
Location: Oslo, Oslo, Norway

www.glennbech.com

ARCHIVES
May 2005 / June 2005 / July 2005 / January 2006 / February 2006 / June 2006 / July 2006 / August 2006 / October 2006 / November 2006 / March 2007 /


Powered by Blogger