You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by abhishek reddy <ab...@gmail.com> on 2009/04/18 10:46:42 UTC

Focus on error fields when validation fails

hi all,

how to highlight error fields in struts html form when validation fails i.e i
want my cursor focus on the error field when validation fails. ?

Note: Validations are performed on the server side (validate() method of
respective form bean)

this is what iam doing...


ActionMessages errors = new ActionMessages();

        if (form.getName() == null || form.getName().trim().length() == 0) {
            errors.add("name", new ActionMessage("name.error.required"));
            check=true;
        }
        else
        if (form.getId() == null || form.getId().trim().length() == 0) {
            errors.add("id", new ActionMessage("id.error.required"));

        }

Note: where "name" and "id" refers to struts html field names?
do i need to make any addtional changes to make it happen?

Please let me know, is it possible to retrieve the error field name on the
client side when validation fails....

-- 
Abhishek

Re: Focus on error fields when validation fails

Posted by Suneel <su...@gmail.com>.
Take a look at documentation for both tags. The property attribute is
what you are looking. Pls read the documentation before posting.

On Sat, Apr 18, 2009 at 2:07 PM, abhishek reddy
<ab...@gmail.com> wrote:
> thanks for the reply...it will just let me know if error messages are
> present or not...
> is it possible to retrieve error field name from it.
>
>
> On Sat, Apr 18, 2009 at 7:23 AM, Suneel <su...@gmail.com> wrote:
>
>> You need to use these tags:
>> <logic:messagesPresent>
>> <html:message>
>>
>>
>> On Sat, Apr 18, 2009 at 3:46 AM, abhishek reddy
>> <ab...@gmail.com> wrote:
>> > hi all,
>> >
>> > how to highlight error fields in struts html form when validation fails
>> i.e i
>> > want my cursor focus on the error field when validation fails. ?
>> >
>> > Note: Validations are performed on the server side (validate() method of
>> > respective form bean)
>> >
>> > this is what iam doing...
>> >
>> >
>> > ActionMessages errors = new ActionMessages();
>> >
>> >        if (form.getName() == null || form.getName().trim().length() == 0)
>> {
>> >            errors.add("name", new ActionMessage("name.error.required"));
>> >            check=true;
>> >        }
>> >        else
>> >        if (form.getId() == null || form.getId().trim().length() == 0) {
>> >            errors.add("id", new ActionMessage("id.error.required"));
>> >
>> >        }
>> >
>> > Note: where "name" and "id" refers to struts html field names?
>> > do i need to make any addtional changes to make it happen?
>> >
>> > Please let me know, is it possible to retrieve the error field name on
>> the
>> > client side when validation fails....
>> >
>> > --
>> > Abhishek
>> >
>>
>>
>>
>> --
>> Thanks
>> Suneel
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
> Abhishek
>



-- 
Thanks
Suneel

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Focus on error fields when validation fails

Posted by abhishek reddy <ab...@gmail.com>.
thanks for the reply...it will just let me know if error messages are
present or not...
is it possible to retrieve error field name from it.


On Sat, Apr 18, 2009 at 7:23 AM, Suneel <su...@gmail.com> wrote:

> You need to use these tags:
> <logic:messagesPresent>
> <html:message>
>
>
> On Sat, Apr 18, 2009 at 3:46 AM, abhishek reddy
> <ab...@gmail.com> wrote:
> > hi all,
> >
> > how to highlight error fields in struts html form when validation fails
> i.e i
> > want my cursor focus on the error field when validation fails. ?
> >
> > Note: Validations are performed on the server side (validate() method of
> > respective form bean)
> >
> > this is what iam doing...
> >
> >
> > ActionMessages errors = new ActionMessages();
> >
> >        if (form.getName() == null || form.getName().trim().length() == 0)
> {
> >            errors.add("name", new ActionMessage("name.error.required"));
> >            check=true;
> >        }
> >        else
> >        if (form.getId() == null || form.getId().trim().length() == 0) {
> >            errors.add("id", new ActionMessage("id.error.required"));
> >
> >        }
> >
> > Note: where "name" and "id" refers to struts html field names?
> > do i need to make any addtional changes to make it happen?
> >
> > Please let me know, is it possible to retrieve the error field name on
> the
> > client side when validation fails....
> >
> > --
> > Abhishek
> >
>
>
>
> --
> Thanks
> Suneel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Abhishek

Re: Focus on error fields when validation fails

Posted by Suneel <su...@gmail.com>.
You need to use these tags:
<logic:messagesPresent>
<html:message>


On Sat, Apr 18, 2009 at 3:46 AM, abhishek reddy
<ab...@gmail.com> wrote:
> hi all,
>
> how to highlight error fields in struts html form when validation fails i.e i
> want my cursor focus on the error field when validation fails. ?
>
> Note: Validations are performed on the server side (validate() method of
> respective form bean)
>
> this is what iam doing...
>
>
> ActionMessages errors = new ActionMessages();
>
>        if (form.getName() == null || form.getName().trim().length() == 0) {
>            errors.add("name", new ActionMessage("name.error.required"));
>            check=true;
>        }
>        else
>        if (form.getId() == null || form.getId().trim().length() == 0) {
>            errors.add("id", new ActionMessage("id.error.required"));
>
>        }
>
> Note: where "name" and "id" refers to struts html field names?
> do i need to make any addtional changes to make it happen?
>
> Please let me know, is it possible to retrieve the error field name on the
> client side when validation fails....
>
> --
> Abhishek
>



-- 
Thanks
Suneel

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org