views:

49

answers:

2

Hello everyone,

I am experiencing problems with localization.

i am using

JSF 2.0 Mojarra (xhtml not jsp) (2.02 - FCS) IceFaces Core 2.0.0 - beta1 IceFaces Compatibility Library v2.0.0. - beta1

Here is the sample of the xhtml page.

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:ice="http://www.icesoft.com/icefaces/component"&gt; 
<h:head> 
<title>"#{msgs.pageTitle}"</title> 
</h:head> 
<h:body> 
<h:form> 
<br /> 
<div align="center"><h:commandButton 
value="#{msgs.serbianLatinAlphabetName}" 
actionListener="#{formSettings.swapLocale1}" immediate="true" /> <h:commandButton 
value="#{msgs.serbianChyrilicAlphabetName}" 
actionListener="#{formSettings.swapLocale1}" immediate="true" /><ice:commandButton 
value="#{msgs.pageTitle}" 
actionListener="#{formSettings.swapLocale1}" immediate="true"/></div> 
</h:form> 
</h:body> 
</html> 

and managed bean:

import java.io.*; 
import java.util.*; 
import javax.faces.bean.*; 
import javax.faces.component.UIViewRoot; 
import javax.faces.context.*; 
import javax.faces.event.*; 

@ManagedBean 
@SessionScoped 
public class FormSettings implements Serializable { 
private boolean isDefault = true; 
private Locale locale = new Locale("sr"); 


public void swapLocale1(ActionEvent event) { 
switchLocale(); 
} 

private void switchLocale() { 
isDefault = !isDefault; 
if (isDefault) { 
locale = new Locale("sr_ME"); 
} else { 
locale = new Locale("sr"); 
} 
//FacesContext.getCurrentInstance().getViewRoot().setLocale(locale); 
FacesContext context = FacesContext.getCurrentInstance(); 
UIViewRoot myViewRoot = context.getViewRoot(); 
myViewRoot.setLocale(locale); 
} 

public Locale getLocale() { 
return locale; 
} 

public void swapLocale2(ValueChangeEvent event) { 
Boolean flag = (Boolean)event.getNewValue(); 
if (flag) { 
switchLocale(); 
} 
} 

public boolean isChecked() { 
return(false); 
} 

public void setChecked(boolean flag) {} 

}

my web.xml is as follows:

<?xml version="1.0" encoding="ASCII"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>WePaminus</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
   <servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/xmlhttp/*</url-pattern>
  </servlet-mapping>
</web-app>

and faces-config.xml :

<?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_2_0.xsd"
 version="2.0">
 <application>
  <locale-config>
   <default-locale>sr</default-locale>
   <supported-locale>sr_ME</supported-locale>
  </locale-config>
  <resource-bundle>
   <base-name>messages</base-name>
   <var>msgs</var>
  </resource-bundle>
 </application>
</faces-config>

The problem is that upon the click on the button, the locale is not changed. Upon manual refresh, the correct locale has been shown.

Could you please help me with this. Have to say that the same page, implemented in pure JSF 2.0 (icefaces excluded) is working perfectly.

Thanks

A: 

You need to re-render the entire page or better, fire a synchronous request instead of an asynchronous (ajaxical) request which would only render the page partially.

BalusC
Hi BalusC,Thank you for the answer. Could you please give me an example. I thouht that actionlistener fires re-ender of the entire page. I have to say, that I see this problem only when I am using icefaces. Wtih JSF 2.0 the UI is changed according to language set in message bundle.In the example a <f:view locale = formSettings.locale> is missing.
Risto
A: 

Hi, here is an update.

I defined a message bundle with full package name in my faces_config.xml. Also I removed, title tag from h:head. Now, language switch works and everything works well. However, when I add this:

    <title>
        <ui:insert name="title">"#{msgs.pageTitle}"</ui:insert>
    </title>

in my head title neither a form or page title is updated. Please, see my faces config below. What am I doing wrong? It really seems that only a part of the page is re-endered.

<?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_2_0.xsd"
    version="2.0">
    <application>
        <locale-config>
            <default-locale>sr</default-locale>
            <supported-locale>sr</supported-locale>
            <supported-locale>sr_me</supported-locale>
        </locale-config>
        <message-bundle>com.somepackage.messages</message-bundle>
        <resource-bundle>
            <base-name>
                rs.paragraf.web.presentation.messages
            </base-name>
            <var>
                msgs
            </var>
        </resource-bundle>
    </application>
</faces-config>
Risto