struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prabhu K M <prabh...@india.adventnet.com>
Subject Re: showing error on forms
Date Tue, 29 Jul 2003 07:02:23 GMT
Hi Vinayak,

You can very well populate the error message near the fields instead of 
showing it in the top. Use the following entry near every fields.
<html:errors property="name"/>

The following example will explain you about how to use it.

In your validate() method you are validating a field. In our case name, if 
the name value is null or its length is less than 1, populate an error 
message.

public ActionErrors validate(ActionMapping map, HttpServletRequest req)
{
         ActionErrors errors=new ActionErrors();
         if(name==null || name.length()<1)
         {
         errors.add("nameMissing", new ActionError("name.missing"));
         }
         return errors;
}

Here the name.missing is the entry made in the MessageResources file.

Add the following in your page near your field,

<html:text property="userId"/>
         <html:errors property="nameMissing"/>

Where nameMissing is the key used when it was added to the ActionErrors 
object. I belive that this will work.


Rgds,
Prabhu.K.M

At 11:29 AM 7/29/2003 +0530, Vinayak Birari wrote:
>Hi,
>
>can anybody tell me how do i show error at particular field insted of
>showing it on top?
>i want, each error fileds LABELs to be shown in red.
>how do i achieve it.
>
>thanks in advance.
>Vinayak.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message