How to change the Struts2 validation error message in the case of an invalid field value?

Posted by FarmBoy on Stack Overflow See other posts from Stack Overflow or by FarmBoy
Published on 2010-03-31T17:30:57Z Indexed on 2010/03/31 17:33 UTC
Read the original article Hit count: 523

Filed under:
|
|
|

I'm using Struts2 validation on a web form. In the case that a field is suppose to be an integer or Date, the <s:fielderror> message I receive is a generic Invalid field value for field "[fieldname]" Naturally, I want to customize this for the user.

Here's an example validation:

<field name="spouseDOB">
    <field-validator type="date">
        <message>"Spouse Date of Birth" is invalid.</message>
    </field-validator>
    <field-validator type="date">
        <param name="min">01/01/1900</param>
        <message>"Spouse Date of Birth" must be after 1900 AD.
    </field-validator>
</field>

The message "Spouse Date of Birth" is invalid. never appears, for any invalid date that I have tried. The output is the generic Invalid field value for field spouseDOB

spouseDOB is a java.util.Date object in the action class. It is set by a <s:textfield> in the JSP.

© Stack Overflow or respective owner

Related posts about struts2

Related posts about java