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

UI Components for JSF
Post Reply
Norberto28
Posts: 1
Joined: 04 Mar 2011, 15:37

04 Mar 2011, 15:52

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

User avatar
Hericksnake
Posts: 47
Joined: 21 Jan 2011, 22:45
Location: Brasil

04 Mar 2011, 16:41

<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

jfosterjr
Posts: 5
Joined: 01 Mar 2011, 23:36

04 Mar 2011, 17:27

The basics include:

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

Code: Select all

Messages_en.properties
contents:

Code: Select all

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

Code: Select all

<?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

Code: Select all

<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 ...

Code: Select all

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

harish.seipl
Posts: 21
Joined: 15 Dec 2010, 07:53

16 Mar 2011, 09:38

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

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 35 guests