Craig,

Is there a way that only the error message(e.g., username is required) appears next to 
the error field instead of the headings:

VALIDATION ERROR
You must correct the following error(s) before proceeding


also appearing with it. It will be good if the heading could be at the top of the page 
and the actual message next to the culprit field.

-Nimmi

-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 31, 2001 6:37 PM
To: [EMAIL PROTECTED]
Subject: Re: question on errors, how to handle


Mike Campbell wrote:

>  I want to be able to have a set of errors returned to an input page
> such that I can spit out an error of a particular TYPE next to a
> particular input, to indicate something in particular was wrong with
> this particular field.  I'm a bit lost on how to accomplish this.Take
> your typical login screen consisting of user name and password.  If
> the login fails, I want the screen to be redrawn with errors that
> pertain to the user name field next to the user name field, and the
> errors associated with the password next to the password field.
> (Ignoring formatting), if my login screen looked
> like:---------------------------------------------------------------Login:
> ___________________Password:
> _____________---------------------------------------------------------------...and
> I typed in "foo9" in user name and nothing in password and given some
> contrived validation rules which will be obvious from the example
> below, I want something like the following to be
> shown:---------------------------------------------------------------Login:
> ____foo9____* The user name must be over 8 characters long* The user
> name must only consist of alphabetic characters.Password:
> _________________* The password was left blank, it must be
> provided.---------------------------------------------------------------Figuring
> out all these conditions, constructing the ActionError class with the
> ApplicationResources.properties key and adding the ActionErrors to the
> request is pretty simple, but I'm lost on the "how to assign an error
> to a particular input field" concept.Is this covered in the
> example?Thanks. --
>

  Mike Campbell     Email: [EMAIL PROTECTED]
  S1 Corporation    voice: 678.421.4641
  Software Engineer fax: 678.421.4865
  R & D             web: http://www.s1.com/
  Black Knight
>

When you store an error in the ActionErrors collection, you have the
option to associate it with a particular field:

    ActionErrors errors = new ActionErrors();
    String username = formBean.getUsername();
    String password = formBean.getPassword();
    if ((username == null) || (username.length() < 1)
        errors.add(new ActionError("username",
            "error.username.required"));
    ... and so on ...

Although the example app does not do so, you can utilize a recently
added feature of the <html:errors> tag to place the messages where you
want:

    ... prompt and field for the "username" field ...
    <html:errors property="username"/>

    ... prompt and field for the "password" field ...
    <html:errors property="password"/>

Craig McClanahan

Reply via email to