husted      2002/09/06 14:48:53

  Modified:    contrib/scaffold/src/java/org/apache/struts/scaffold
                        BaseForm.java
  Log:
  + ActionForm: Add remoteAddr property (automatic). Add validate
  method that will not return null.
  
  Revision  Changes    Path
  1.4       +68 -20    
jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseForm.java
  
  Index: BaseForm.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseForm.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseForm.java     16 Aug 2002 22:29:24 -0000      1.3
  +++ BaseForm.java     6 Sep 2002 21:48:52 -0000       1.4
  @@ -12,8 +12,11 @@
   import org.apache.struts.util.BeanUtils; // Struts 1.0.x
   
   import org.apache.struts.action.Action;
  +import org.apache.struts.action.ActionError;
  +import org.apache.struts.action.ActionErrors;
   import org.apache.struts.action.ActionMapping;
  -import org.apache.struts.validator.ValidatorForm;
  +// import org.apache.struts.validator.ValidatorForm; // Struts 1.1
  +import com.wintecinc.struts.action.ValidatorForm;
   
   import org.apache.commons.scaffold.lang.ChainedException;
   
  @@ -31,6 +34,33 @@
   // ----------------------------------------------------------- Properties
   
       /**
  +     * The network address making this request.
  +     * <p>
  +     * This is the value returned by reqest.getRemoteAddr.
  +     * It is provided so that this can be logged by components on
  +     * the business tier if needed.
  +     * This property is maintained automatically through the
  +     * <code>reset</code> method.
  +     */
  +    private String remoteAddr = null;
  +
  +    /**
  +     * Return our remoteAddr property.
  +     */
  +    public String getRemoteAddr() {
  +        return (this.remoteAddr);
  +    }
  +
  +
  +    /**
  +     * Set our remoteAddr property.
  +     */
  +    public void setRemoteAddr(String remoteAddr) {
  +        this.remoteAddr = remoteAddr;
  +    }
  +
  +
  +    /**
        * Our locale property.
        * <p>
        * If the formBean instance is mutable, this is set to the Struts
  @@ -119,6 +149,42 @@
   // --------------------------------------------------------- Public Methods
   
       /**
  +     * If bean is set to mutable, calls <code>resetSessionLocale</code>
  +     * and <code>setRemoteAddr</code>.
  +     *
  +     * Subclasses resetting their own fields should observe the mutable
  +     * state (<code>if (isMutable()) ...</code>).
  +     *
  +     * @param mapping The mapping used to select this instance
  +     * @param request The servlet request we are processing
  +     */
  +    public void reset(
  +            ActionMapping mapping,
  +            HttpServletRequest request) {
  +
  +        if (isMutable()) {
  +
  +            resetSessionLocale(request);
  +            setRemoteAddr(request.getRemoteAddr());
  +        }
  +
  +    } // end reset
  +
  +
  +    /**
  +     * Return an empty ActionErrors or the result of calling
  +     * the superclass validate. Will not return null.
  +     */
  +    public ActionErrors validate(ActionMapping mapping,
  +        HttpServletRequest request) {
  +
  +        ActionErrors errors = super.validate(mapping,request);
  +        if (null==errors) errors = new ActionErrors();
  +        return errors;
  +    }
  +
  +
  +    /**
        * Reset our locale property to the locale object found in
        * the session associated with this request.
        */
  @@ -151,24 +217,6 @@
           request.getSession(true).setAttribute(Action.LOCALE_KEY,locale);
   
       } // end putSessionLocale
  -
  -
  -    /**
  -     * If bean is set to mutable, calls <code>resetSessionLocale()</code>.
  -     *
  -     * Subclasses resetting their own fields should observe the mutable
  -     * state (<code>if (isMutable()) ...</code>).
  -     *
  -     * @param mapping The mapping used to select this instance
  -     * @param request The servlet request we are processing
  -     */
  -    public void reset(
  -            ActionMapping mapping,
  -            HttpServletRequest request) {
  -
  -        if (isMutable()) resetSessionLocale(request);
  -
  -    } // end reset
   
   
       /**
  
  
  

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

Reply via email to