You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Struts2 Fan <st...@gmail.com> on 2007/02/03 23:20:50 UTC

will validation include custom error tag in the next releases?

Hi all,

I really don't like the position of the validation messages. And I
want to use theme="simple" tags always.
So I wonder if we can have the opportunity to have a validation
message such below.

<td>
<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.

will there be such an option for validation?

If not, please show me a way where to start making such an
implementation :) Because i really want the validation messages
be this way.

Thanks all,

Re: will validation include custom error tag in the next releases?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----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


Re: will validation include custom error tag in the next releases?

Posted by Dave Newton <ne...@yahoo.com>.
--- Struts2 Fan <st...@gmail.com> wrote:
> [...] So I wonder if we can have the opportunity to 
> have a validation message such below.
> [...] will there be such an option for validation?

http://cwiki.apache.org/WW/themes-and-templates.html

d.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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