struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shamdasani Nimmi-ANS004 <>
Subject RE: question on errors, how to handle
Date Thu, 01 Feb 2001 16:51:07 GMT

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

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.


-----Original Message-----
From: Craig R. McClanahan []
Sent: Wednesday, January 31, 2001 6:37 PM
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
> 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:
  S1 Corporation    voice: 678.421.4641
  Software Engineer fax: 678.421.4865
  R & D             web:
  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",
    ... 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

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

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

Craig McClanahan

View raw message