struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/action ActionForm.java ActionResources.properties ActionServlet.java
Date Sun, 15 Oct 2000 03:29:16 GMT
craigmcc    00/10/14 20:29:16

  Modified:    src/share/org/apache/struts/action ActionForm.java
                        ActionResources.properties ActionServlet.java
  Log:
  ActionForm updates:
  - Make ActionForm serializable so that Struts-based applications can be
    used in servlet containers that enforce "distributable" semantics.
  - Change reset() method signature so that it receives the mapping
    selecting this bean and the request object, to provide context for
    making property reset decisions in multi-page forms.
  
  ActionServlet updates:
  - Skip input form validation if there is no input attribute defined in
    an <action> mapping.
  - Skip input form validation if the Cancel key was pressed to submit
    this form.
  
  Revision  Changes    Path
  1.3       +35 -10    jakarta-struts/src/share/org/apache/struts/action/ActionForm.java
  
  Index: ActionForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForm.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ActionForm.java	2000/10/12 21:51:01	1.2
  +++ ActionForm.java	2000/10/15 03:29:15	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForm.java,v
1.2 2000/10/12 21:51:01 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/10/12 21:51:01 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForm.java,v
1.3 2000/10/15 03:29:15 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/15 03:29:15 $
    *
    * ====================================================================
    * 
  @@ -63,6 +63,7 @@
   package org.apache.struts.action;
   
   
  +import java.io.Serializable;
   import javax.servlet.ServletRequest;
   import javax.servlet.http.HttpServletRequest;
   
  @@ -91,10 +92,10 @@
    * </p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/10/12 21:51:01 $
  + * @version $Revision: 1.3 $ $Date: 2000/10/15 03:29:15 $
    */
   
  -public abstract class ActionForm {
  +public abstract class ActionForm implements Serializable {
   
   
       // ----------------------------------------------------- Instance Variables
  @@ -140,10 +141,34 @@
        * Reset all bean properties to their default state.  This method is
        * called before the properties are repopulated by the controller servlet.
        * <p>
  +     * The default implementation attempts to forward to the HTTP
  +     * version of this method.
  +     *
  +     * @param mapping The mapping used to select this instance
  +     * @param request The servlet request we are processing
  +     */
  +    public void reset(ActionMapping mapping, ServletRequest request) {
  +
  +        try {
  +            reset(mapping, (HttpServletRequest) request);
  +        } catch (ClassCastException e) {
  +            ;
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Reset all bean properties to their default state.  This method is
  +     * called before the properties are repopulated by the controller servlet.
  +     * <p>
        * The default implementation does nothing.  Subclasses should override
        * this method to reset all bean properties to default values.
  +     *
  +     * @param mapping The mapping used to select this instance
  +     * @param request The servlet request we are processing
        */
  -    public void reset() {
  +    public void reset(ActionMapping mapping, HttpServletRequest request) {
   
           ;       // Default implementation does nothing
   
  @@ -160,8 +185,8 @@
        * The default implementation attempts to forward to the HTTP version of
        * this method.
        *
  -     * @param mapping The ActionMapping used to select this instance
  -     * @param request The non-HTTP request we are processing
  +     * @param mapping The mapping used to select this instance
  +     * @param request The servlet request we are processing
        */
       public ActionErrors validate(ActionMapping mapping,
                                    ServletRequest request) {
  @@ -186,8 +211,8 @@
        * <code>null</code>.  Subclasses must override this method to provide
        * any validation they wish to perform.
        *
  -     * @param mapping The ActionMapping used to select this instance
  -     * @param request The HTTP servlet request we are processing
  +     * @param mapping The mapping used to select this instance
  +     * @param request The servlet request we are processing
        */
       public ActionErrors validate(ActionMapping mapping,
                                    HttpServletRequest request) {
  
  
  
  1.4       +1 -0      jakarta-struts/src/share/org/apache/struts/action/ActionResources.properties
  
  Index: ActionResources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionResources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ActionResources.properties	2000/10/07 22:55:13	1.3
  +++ ActionResources.properties	2000/10/15 03:29:15	1.4
  @@ -7,6 +7,7 @@
   configMissing=Missing configuration resource for path {0}
   configParse=Parsing error processing resource path {0}
   finalizing=Finalizing this controller servlet
  +noInput=No input attribute for mapping path {0}
   processInvalid=Invalid path {0} was requested
   processPath=No process path included in this request
   reloading=Reloading from configuration files
  
  
  
  1.30      +60 -13    jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ActionServlet.java	2000/10/12 21:51:03	1.29
  +++ ActionServlet.java	2000/10/15 03:29:15	1.30
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.29 2000/10/12 21:51:03 craigmcc Exp $
  - * $Revision: 1.29 $
  - * $Date: 2000/10/12 21:51:03 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.30 2000/10/15 03:29:15 craigmcc Exp $
  + * $Revision: 1.30 $
  + * $Date: 2000/10/15 03:29:15 $
    *
    * ====================================================================
    *
  @@ -150,6 +150,9 @@
    *     resources bundle base class.  [NONE].</li>
    * <li><strong>config</strong> - Context-relative path to the XML resource
    *     containing our configuration information.  [/WEB-INF/action.xml]</li>
  + * <li><strong>content</strong> - Default content type and character
encoding
  + *     to be set on each response; may be overridden by a forwarded-to
  + *     servlet or JSP page.  [text/html]</li>
    * <li><strong>debug</strong> - The debugging detail level for this
    *     servlet, which controls how much information is logged.  [0]</li>
    * <li><strong>detail</strong> - The debugging detail level for the Digester
  @@ -197,7 +200,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.29 $ $Date: 2000/10/12 21:51:03 $
  + * @version $Revision: 1.30 $ $Date: 2000/10/15 03:29:15 $
    */
   
   public class ActionServlet
  @@ -227,6 +230,13 @@
   
   
       /**
  +     * The default content type and character encoding to be set on each
  +     * response (may be overridden by forwarded-to resources).
  +     */
  +    protected String content = "text/html";
  +
  +
  +    /**
        * The debugging detail level for this servlet.
        */
       protected int debug = 0;
  @@ -968,9 +978,13 @@
        */
       protected void initOther() throws ServletException {
   
  -	// Process the "locale" and "nocache" initialization parameters
  +	// Process the "content", "locale", and "nocache" parameters
   	String value = null;
   
  +        value = getServletConfig().getInitParameter("content");
  +        if (value != null)
  +            content = value;
  +
           value = getServletConfig().getInitParameter("locale");
           if (value != null) {
               if ("true".equalsIgnoreCase(value) ||
  @@ -1024,7 +1038,8 @@
           // Automatically select a locale for this user if requested
           processLocale(request);
   
  -	// Set the no-caching headers if requested
  +	// Set the content type and no-caching headers if requested
  +        processContent(response);
   	processNoCache(response);
   
   	// Look up the corresponding mapping
  @@ -1196,6 +1211,21 @@
   
   
       /**
  +     * Set the default content type (with optional character encoding) for
  +     * all responses.  This value may be overridden by forwarded-to servlets
  +     * or JSP pages.
  +     *
  +     * @param response The response we are processing
  +     */
  +    protected void processContent(HttpServletResponse response) {
  +
  +        if (content != null)
  +            response.setContentType(content);
  +
  +    }
  +
  +
  +    /**
        * Automatically calculate an appropriate <code>java.util.Locale</code>
        * for this user, and store it in their session, if there is no such
        * Locale object present already.
  @@ -1353,7 +1383,7 @@
           // Populate the bean properties of this ActionForm instance
           if (debug >= 1)
               log(" Populating bean properties from this request");
  -        formInstance.reset();
  +        formInstance.reset(mapping, request);
           BeanUtils.populate(formInstance, mapping.getPrefix(),
                              mapping.getSuffix(), request);
   
  @@ -1383,18 +1413,35 @@
   
           if (formInstance == null)
               return (true);
  +        if (debug >= 1)
  +            log(" Validating input form properties");
   
  +        // Has an input form been specified for this mapping?
  +	String uri = mapping.getInput();
  +        if (uri == null) {
  +            if (debug >= 1)
  +                log("  No input form, no validation");
  +            return (true);
  +        }
  +
  +        // Was this submit cancelled?
  +	if (request.getParameter(Constants.CANCEL_PROPERTY) != null) {
  +            if (debug >= 1)
  +                log("  Cancelled transaction, no validation");
  +            return (true);
  +        }
  +
           // Call the validate() method of our ActionForm bean
  -        if (debug >= 1)
  -            log(" Calling form validation method");
           ActionErrors errors = formInstance.validate(mapping, request);
  -        if ((errors == null) || errors.empty())
  +        if ((errors == null) || errors.empty()) {
  +            if (debug >= 1)
  +                log("  No errors detected, accepting input");
               return (true);
  +        }
   
  -	// Save our error messages and return to the input form
  -	String uri = mapping.getInput();
  +	// Save our error messages and return to the input form if possible
   	if (debug >= 1)
  -	    log(" Form validation error: redirecting to: " + uri);
  +	    log("  Validation error(s), redirecting to: " + uri);
   	request.setAttribute(Action.ERROR_KEY, errors);
   	RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
   	rd.forward(request, response);
  
  
  

Mime
View raw message