Hi,

My friend, Lee Crawford, just pointed out to me that the fields of the
ActionForm will be null if the validate method is called before the form is
submitted, but will be non-null afterwards. This provides a quick and simple
test that works for JSP called pages and for Action called pages,


       public ActionErrors validate (ActionMapping mapping,
     HttpServletRequest request) {
             // See if the form has been submitted, if not do not
     validate.
             if (logon == null || password == null ) return null;
             // Validate the data
             final ActionErrors errors = new ActionErrors ();
             if (logon.length() < 1) {
                 errors.add ("logon", new ActionError
     ("error.logon.logonRequired"));
             }
             if (password.length() < 1) {
                 errors.add("password", new ActionError
     ("error.logon.passwordRequired"));
             }
             return errors;
         }


Sid

Sid Stuart wrote:

> Hi,
>
> I've stumbled across a subtle problem/design question that I don't see
> mentioned in the documentation.
>
> The ActionForm's validate method can be configured to verify form data
> from a page and generate error messages which may then be displayed on
> the page for the user to see. This works fine when the user has accessed
> the page by specifying a JSP file in the URL. When the user accesses the
> page by calling the Action directly though, the validate method is
> called before the user ever sees the page, much less inputs valid data
> to the form. This leads to an unfortunate display of unwarranted error
> messages.
>
> It would be nice if the documentation would provide a rule such as:
> If one plans on the user calling the Action directly in the URL  then
> one should not use the automatic validation provided by ActionForm.
>
> Further, as having two different procedures to generate a page can lead
> to subtle errors, one should decide whether a page will be accessed as a
> JSP or as an Action and design for the one scenario. The simplest (and
> safest) design rule will be to access all pages through either one
> mechanism or the other.
>
> Comments?
>
> Sid Stuart

Reply via email to