hi dear sir
My example is very simple but it has one bug that it does not show the Arabic text in spite of changing locale . It shows jargon of
1 – localeChanger.jsp which is simply 3 radio boxes for locale selection which would display the welcome word accordingly
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html lang="ar" dir="rtl">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<f:view locale="#{localeChanger.locale}">
<html>
<head> <title></title> </head>
<body bgcolor="white">
<h:form>
<h:panelGrid columns="2">
<f:facet name="label">
<h:outputText value="#{labels.prefLangHeader}" />
</f:facet>
<h:outputText value="Choose a language" /> <br/>
<h:selectOneRadio value="#{localeChanger.locale}">
<f:selectItem itemValue="en" itemLabel="English"/>
<f:selectItem itemValue="de" itemLabel="German"/>
<f:selectItem itemValue="ar" itemLabel="Arabic"/>
</h:selectOneRadio>
</h:panelGrid>
<h:commandButton value="Submit" action="#{localeChanger.changeLocale}" />
</h:form>
<h:outputText value="#{message.welcome}" />
</body>
</html>
</f:view>
2 – bean which only changes the locale
package internationlise;
import java.util.Locale;
import javax.faces.context.FacesContext;
public class LocaleChanger {
private String locale ;
public String getLocale() {return locale;}
public void setLocale(String locale) {this.locale = locale;}
public String changeLocale (){
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(getLocale()));;
return null;
}
}
3 - faces-config.xml which shows the locales and the properties package
<?xml version='1.0' encoding='UTF-8'?>
<faces-config 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_1_2.xsd"
version="1.2">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>ar</supported-locale>
</locale-config>
<resource-bundle>
<base-name>bundles.Messages</base-name>
<var>message</var>
</resource-bundle>
</application>
<managed-bean>
<managed-bean-name>localeChanger</managed-bean-name>
<managed-bean-class>internationlise.LocaleChanger</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
4 -. properties which contains one word each of welcome
Messages.propertie welcome=Welcome
Messages_ar.properties welcome=شس شس
Messages_en.properties welcome=Welcome
Messages_de.properties welcome=Welcomeen
5 – Notes :
1 – I use tha UTF-8 encoding in the jsp file as above
2 – Also in myeclipse from windows -> preferences -> general -> Content Types -> Text -. UTF-8
Also for jsp but here it restores the default value of ISO-8859-1 i.e does not save it why?
3 – I use windows XP professional supporting English and Arabic
4 – I changed the encoding in internet browser Tools as well
I do appreciate the solution ASAP
Amir