struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: how to generate GLOBAL errors using Struts validation framework
Date Wed, 01 Nov 2006 23:35:11 GMT
You can also do the same kind of thing that Chris suggests with Struts tags:

For your global message, uses the "messagesPresent" tag to detect if
there are errors and then output the appropriate message:

  <logic:messagesPresent>
       <bean:message key="error.title.some-fields-are-bad" />
  </logic:messagesPresent>

For your field specific messages, you can use either the
<html:messages> or <html:errors> tags to position messages next to
their fields

  http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5

Niall


On 11/1/06, Christopher Schultz <chris@christopherschultz.net> wrote:
> Robin,
>
> > When the user submits the form with more than one fields left blank (or
> > with incorrect values), I want to show a
> > general (GLOBAL) message on top of the form saying
> >
> > "Following shown mandatory fields were provided with incorrect values"
>
> How about putting something like this in your JSP (haven't worked with
> JSP in forever, but this ought to get the point across):
>
> <jstl:if test="$errors">
>    <p class="error">
>       <struts:msg key="error.title.some-fields-are-bad" />
>    </p>
> </jstl:if>
>
> > b) And then I want to show a field-specific error message beside each
> > input field that failed the validation rules.
>
> Umm...
>
> <jstl:if test="$errors.form-field-1">
>     <jstl:echo value="$errors.form-field-1" />
> </jstl:if>
> <label for="form-field-1">Field</label>
> <input id="form-field-1" name="form-field-1" ... />
>
> etc.
>
> Does that help?
>
> - -chris

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


Mime
View raw message