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

I am using Struts2 validation in a web form. In the case where the field is considered an integer or Date, the message <s:fielderror> that I receive is a common Invalid field value for field "[fieldname]" Naturally, I want to configure it for the user.

Here is a validation example:

 <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.</message> </field-validator> </field> 

The message "Spouse Date of Birth" is invalid. never appears for any incorrect date I tried. The output is a common Invalid field value for field spouseDOB

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

+4
source share
3 answers

In your ApplicationResources.properties file, paste

 invalid.fieldvalue.spouseDOB = "Spouse Date of Birth" is invalid. 

If you do not have this file, check out this .

+8
source

make one properties file in the same package where your action class is defined

"youactionclassname.properties" and adding an error to it,

like "invalid.fieldvalue.yourfiledname = as you want for error " and do the following.

  • save him
  • and restart the server
  • run

now you can see the error has been configured ...

Tell me if it works

Good luck.

0
source

Well, he lost </message> for one thing

-1
source

Source: https://habr.com/ru/post/1305685/


All Articles