Skip to main content

custom validator messages - why they don't work for me?

2 replies [Last post]
maxqua72
Offline
Joined: 2010-03-31
Points: 0

Hi,
I have a strange situation because I cannot figure out why I cannot change the default validator messages.
My faces-config.xml is the following:

<?xml version="1.0" encoding="UTF-8"?>

com.error.error
com.locale.validationerror
com.rules.chess.chess
com.help.help

com.locale.messages
msgs

en
it
en

captcha.validator.captchaValidator
captcha.validator.captchaValidator

in the file:
/src/com/error/error_en.properties

I've put the following:

javax.faces.component.UIInput.REQUIRED=value is required
javax.faces.validator.LengthValidator.MAXIMUM=more than "{0}" characters
javax.faces.validator.LengthValidator.MINIMUM=less than "{0}" characters
javax.faces.validator.LongRangeValidator.MINIMUM=value too small

but I got
j_idt10:j_idt85:j_idt86:j_idt88:userNameInput: Validation Error: Value is required.

if I submit a form using my custom component (it does not depend on the following component, it happens always):

<?xml version="1.0" encoding="ISO-8859-1" ?>

...................

please could you help understand why I got this unexpected behaviour?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
maxqua72
Offline
Joined: 2010-03-31
Points: 0

I havent' found a fix yet. Please, is there a way to debug in order to find the fault for this case?

maxqua72
Offline
Joined: 2010-03-31
Points: 0

Hi,
I think I have found the strange reason of the odd behaviour. I wonder if this is a fault.
I start playing with the basic-ajax example of mojarra 2.0.2 so that everyone can repeat my test.
I created two message bundle files:
validationerror (_en.properties and _it.properties) and error (_en.properties and _it.properties, of course).

where error files contain my error messages and validationerror contain customized javax.faces.validation messages like:

javax.faces.validator.LengthValidator.MAXIMUM=Value is greater than allowable maximum of "{0}"
javax.faces.validator.LengthValidator.MINIMUM=Value is less than allowable minimum of "{0}"

then I modified the file echo1.xhtml inserting the validator to the element in1 and adding another commandButton






I created a faces-config.xml with:


locale.validationerror
locale.error

locale.messages
msgs


en
it
en

And in this case I got:

form1:in1: Validation Error: Value is less than allowable minimum of '4'

so the custom message didn't work!!

But if I change the order of the message bundles in faces-config file and place the validationerror in the last position:


locale.error
locale.validationerror

locale.messages
msgs


en
it
en

I got:

Value is less than allowable minimum of "4"

so it works!! But why?
Is this a bug? I have more than two message bundles files in my application, so why I have to place the custom validation message files in the last position?