I'm interested in some feedback on the following:

I prefer to develop web applications using a page-centric model. I like the 
simplicity of one JSP <-> one Java class for the view layer (not the model). 
Struts, with its separate Action and ActionForm classes, tends toward at least 
two Java classes for a JSP: an Action, and an ActionForm. This tends toward a 
multiplicity of Java classes. (I know it's possible to share a single 
ActionForm and Action for multiple JSP's, but I'm looking for a simpler 
approach.)

I would like to create a generic Action class that delegates request processing 
to a SimpleActionForm, like this:

public abstract class SimpleActionForm extends ActionForm {
        public abstract ActionForward execute(
                ActionMapping mapping,
                HttpServletRequest request,
                HttpServletResponse response) throws Exception;
}

public class SimpleAction extends Action {
        public ActionForward execute(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
                throws Exception {
                        
                SimpleActionForm bean = (SimpleActionForm)form;
                return bean.execute(mapping, request, response);
        }
}

With this approach, most JSP pages could have a single Java class -- a 
SimpleActionForm subclass that handles both validation and processing for the 
page:

public class LoginForm extends SimpleActionForm {
                
        private String username;
        private String password;
        
      ... getter and setter methods ...

      public abstract ActionForward execute(
                ActionMapping mapping,
                HttpServletRequest request,
                HttpServletResponse response) throws Exception {
         ... Login processing ...
        }
        
        
        public ActionErrors validate(ActionMapping mapping, HttpServletRequest 
req) {
          ... validation code ...
        }

}

Then, in my struts-config.xml file, most form beans would extend the 
SimpleActionForm, and most actions would use the SimpleAction type:

  <form-beans>
    <form-bean name="loginform" type="LoginForm" /> <!-- extends 
SimpleActionForm -->
  </form-beans>

  <action path="/login" type="SimpleAction" name="loginform" scope="request" 
    validate="true" input="/login.jsp">
        ...
  </action>


I don't have a lot of experience with Struts, so I'm interested on feedback 
about this approach. Is it a good/bad idea? If bad, why? 

Thanks in advance,

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to