webtier@glassfish.java.net

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

From: <webtier_at_javadesktop.org>
Date: Sat, 08 May 2010 09:21:25 PDT

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

        <h:inputText id="in1" value="#{echo.str}" required="true">
               <f:validateLength minimum="4" maximum="15"/>
        </h:inputText>
        <br/>
        <h:commandButton id="button2" value="Echo2"></h:commandButton>


I created a faces-config.xml with:

<application>
                <message-bundle>locale.validationerror</message-bundle>
                <message-bundle>locale.error</message-bundle>
                <resource-bundle>
                        <base-name>locale.messages</base-name>
                        <var>msgs</var>
                </resource-bundle>
                <locale-config>
                        <default-locale>en</default-locale>
                        <supported-locale>it</supported-locale>
                        <supported-locale>en</supported-locale>
                </locale-config>
</application>

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:

<application>
                <message-bundle>locale.error</message-bundle>
                <message-bundle>locale.validationerror</message-bundle>
                <resource-bundle>
                        <base-name>locale.messages</base-name>
                        <var>msgs</var>
                </resource-bundle>
                <locale-config>
                        <default-locale>en</default-locale>
                        <supported-locale>it</supported-locale>
                        <supported-locale>en</supported-locale>
                </locale-config>
</application>

 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?
[Message sent by forum member 'maxqua72']

http://forums.java.net/jive/thread.jspa?messageID=469015