struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: will validation include custom error tag in the next releases?
Date Sat, 03 Feb 2007 23:34:35 GMT
Hash: SHA1


Struts2 Fan wrote:
> <s:textfield name="age" theme="simple"/><div name="ageerror"><img
> src="images/hata.jpg"></div>
> </td>
> I want to define a validation for Age field as it is an example on
> the site. But if it is an invalid field I want the "ageerror" div to
> be visible and if not invisible.

You should be able to do this no matter what version of Struts and
validator you are using. First of all, you need to change your error
message in your validator config ('required' and 'mask' are just
examples of validations to perform on this field):

    <field name="age" requires="required, mask">
	<msg name="required" bundle="myBundle"
            key="error.ageerror" />
	<msg name="mask" bundle="myBundle"
            key="error.ageerror" />

This will configure your message "error.ageerror" for display whenever
there is an error with your "age" field. In this way, you can override
the default error message that is displayed by any validator for any field.

Next, you need to configure your age error message in your bundle file:

error.ageerror=<div name="ageerror"><img src="images/hata.jpg" /></div>

Finally, simply use the existing error message JSP tags (I am unfamiliar
with them since I don't use JSP, but I'm sure it's something like this:)

<s:textfield name="age" theme="simple" />
<s:errormsg fieldName="age" />

That's all you should need.

- -chris
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message