header image
Home arrow Computing arrow Software Development arrow requiredMessage attribute for JSF 1.2 inputText
requiredMessage attribute for JSF 1.2 inputText PDF Print E-mail
Jul 25, 2007 at 11:13 AM

To be able to display localized/multilingual error messages at the "requiredMessage" Attribute of JSF1.2 h:inputText components it is not enough to simple reference the message bundle via EL expression that was defined in the page itself with f:loadBundle.

The reason for this is the lifecycle of the f:loadBundle definition:

The reason for this behaviour is that f:loadBundle sets the message bundle into the var name as a request scoped attribute only. The "requiredMessage" expression is evaluated during the validation phase after a post-back, by which time the original request scope no longer exists (the f:loadBundle won't get invoked again until the render-response phase).

(Taken from Tony Robertson http://forum.java.sun.com/thread.jspa?threadID=754189&messageID=4317895)

With JSF1.2 it is possible to define a variable name for a resource bundle directly in faces-config.xml, this allows to reference the resource bundle by the variable name via EL expression within the requiredMessage attribute of h:inputText components for example:

faces-config.xml:

=== 

<application>
        ...
        <message-bundle>messages</message-bundle>
        <resource-bundle>
            <base-name>messages</base-name>
            <var>msg</var>
        </resource-bundle>
   </application>

 

JSF page:

===

...

<h:inputText ... requiredMessage="#{msg.this_value_is_required}"/> 

A man is truly ethical only when he
obeys the compulsion to help all life which
he is able to assist, and shrinks from
injuring anything that lives.

Albert Schweizer