The moose likes JSF and the fly likes how to customize error messages Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "how to customize error messages" Watch "how to customize error messages" New topic
Author

how to customize error messages

alisha chenna
Greenhorn

Joined: May 01, 2007
Posts: 7
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

Joined: Jun 05, 2007
Posts: 19
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to customize error messages
 
Similar Threads
comparision between two dates
Custom message box using Swings
Question on Creation of a Date Object
Comparing 2 Dates
Validating date using regex and simple date format