struts-user mailing list archives

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

SF,

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" />
        .
        .
        .
    </field>

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:

myBundle.properties:

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFxRwL9CaO5/Lv0PARAorhAJ9XOKWRNmsvb/gzSMBWm/G7z8INsQCeKns+
X9TwBK8XmiSqG8P/hVBmhag=
=aKRT
-----END PGP SIGNATURE-----

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


Mime
View raw message