My frustration started while finishing a personal application using the widely-used MVC framework Struts. I already had lots of "controlled" Actions and I was just adding a new Action to the play, but I was trying to be Agile :D I had downloaded the newest version of Eclipse 3.3 and imported my project accordingly. Then, I promptly just fired the "Create New Class" and extended the Action. That's it!!! (I thought), but my headache had just started after I trusted my loved IDE's auto-completion capabilities.
Before I describe what I had implemented on my execute method (the one we must override in order to have our application to "dance"), I found descriptions of which mistakes one can make in order to get the so-called blank/white page result after executing a strusts action. My application was also suffering from this well-known and poorly documented problem. According to a post at JMatrix, 2 are the possibilities of getting this blank page side-effect: If the Default Action is called instead of your Action class or if the input class on the action mapping is invalid. However, I'm writing this post just to add my 2 cents to the scope of this problem. Everything started when I trusted Eclipse to override the method signature below:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)This is the correct signature of the method execute, the one that will be executed by the Action Executor. However, after using the code-completion feature, I got the following signature:
/* (non-Javadoc)Being agile is all about trusting the tools that help you be productive, and this was just a moment of sadness. For me, the code was totally correct, but it was completed with a different signature. Although the action is loaded, nothing will be executed with this scenario. I spent a few hours with the clue of just having, among others, the following lines of the debugger output that proved that my Action class was being created and used by the Action executor class ActionCommandBase to execute the default "execute method".
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response)
throws Exception {
00:48:11,658 DEBUG CreateForumPosterAction:27 - Starting the create forum poster action...Any clues? The reason is that the method added was not overriding, but overloading the method execute from the class AbstractAction, which is just an empty method. Therefore, another reason to get the blank page from the execution of an Action struts class is when you trust an IDE such as Eclipse and hope that it will auto-complete the overridden method when you need. In other words, my 2 cents for JMatrix list is:
00:48:11,659 DEBUG AbstractCreateAction:93 - setting action to net.jsurfer.cryptonline.client.web.CreateForumPosterAction@192563a
00:48:11,660 DEBUG ActionCommandBase:49 - Executing org.apache.struts.chain.commands.servlet.ExecuteAction
3. If you have NOT overridden the method execute, but overloaded it by having a different method signature. Be careful!!! It is HttpServletRequest and HttpServletResponse instead of ServletRequest and Servlet Response on the signature of the execute method. Never trust your loved IDE.
No comments:
Post a Comment