• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to customize error messages

 
alisha chenna
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a date field.If i enter the date in any other format other than mm/dd/yy it should display a custom message rather than a standard message. How can i achieve this.

Thanks,
Alisha.
 
Tak Ng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the validator you are using on this date field. Please follow these steps:

1) First, add a message bundle to your jsp page in the <head> section. Below is an example:
<f:loadBundle basename="com.xyz.messages" var="msgs"/>

2) You need to create for the above example a file called "messages.properties" in the package com/xyz (change it for the package of your application).

3) On your faces-config.xml, add
<faces-config>
...
<application>
<message-bundle>com.xyz.messages</message-bundle>
</application>
...
</faces-config>

4) Inside "messages.properties", replace the resource ID of the validator you are using with a custom message you want to set. For example, if you use the standard length validator that comes with jsf, you can overwrite the custom message of maximum length with the following line:

javax.faces.validator.LengthValidator.MAXIMUM=You have passed the maximum value allowed for this field.

Since I don't know which validator your are using, you have to look at the API documentation of your validator the corresponding Resource ID (javax.faces.validator.LengthValidator.MAXIMUM is the Resource ID of the previous example).

For reference, you can get a copy of Laxxuss' "Core JavaServer Faces". It is a good book on JSF.

Hope it helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!