Board index JavaServer Faces General Translate <p:message /> and <p:messages /> message

Translate <p:message /> and <p:messages /> message

Components, Ajax Framework, Utilities and More.


Posts: 1
Hi all,

I'm new in primefaces, and my first bigger problem is how can I translate the <p:message />'s message (for example: text:Validation Error:Value is required) to my language? Where can I configuring it? In css, or somewhere in configuring files, or can i set it up in the bean?

Thans a lot.

Norberto


Posts: 47
Location: Brasil
<p:message>

You will use it when you have a p:inputText for example, and that needs a validator or is a required camp. So, you need to put an "id" for the input and show this id in the "for" of the <p:message>

<p:messages>
If you have to show lot of errors or messages on your application. This will receive all facesContext messages that you send for him. It will be used for general messages.

If someone use this to different purposes, please reply!
;)
Primefaces 3.2
JSF 2.0
Glassfish Server 3.1.2
Netbeans7.1.1


Posts: 5
The basics include:

1. Create a properties file that will hold your localized messages.
filename:
Messages_en.properties

contents:
validation_error_message=Text field failed validation


You would create a properties file resource bundle following the L10N naming convention for your desired language. (e.g. Messages_es.properties)

2. Declare the properties resource bundle in faces-config.xml

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

<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
       
    <application>
        <resource-bundle>
            <base-name>test.Messages</base-name>
            <var>msg</var>
        </resource-bundle>
        <locale-config>
            <supported-locale>en</supported-locale>
            <default-locale>en</default-locale>
        </locale-config>
    </application>

</faces-config>


3. Refer to the localized message either in a tag parameter or in bean validation code as follows (these are just examples, there are a couple difference ways to use them)

in a validatorMessage attribute of an input tag tag

<p:inputText id="it1" value="#{testPageBean.text1}" validatorMessage="#{msg['validation_error_message']}">
    <f:validateRegex pattern="[\d]{1,}" />
</p:inputText>
<p:message for="it1"/>


...or in a bean method ...

FacesContext ctx = FacesContext.getCurrentInstance();
Locale locale = ctx.getViewRoot().getLocale();
ResourceBundle rb = ResourceBundle.getBundle("test.Messages", locale);
String str = rb.getString("validation_error_message");


Posts: 21
Hey is there any ways to update p:messgae from managed bean.Now iam using Faces messges in back end bean and i could display the content only in growl and not through p:messgae.Iam struggling a lot over this .please help me


Return to General