Enira
Legacy Member
Ik zit dus met een layout probleem in het maken van mijn JSF applicatie. Bij de submit van de knoppen wordt de <f:view locale... eerst uitgevoerd en dan pas wordt de locale gezet. Waardoor ik twee keer moet drukken op de knop. Hoe kan ik ervoor zorgen dat de locale eerst gezet wordt alvorens dat de pagina geladen wordt?
Code:
Code:
Code:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="#{locoBean.locale}" id="pageView">
<f:loadBundle basename="web.MessageResources" var="msg"/>
<h:head>
<title>#{msg.welcome}</title>
</h:head>
<h:body>
<h:outputText value="#{msg.welcome}" />
<h:form >
<h:commandButton value="en_US">
<f:setPropertyActionListener value="#{'en_US'}" target="#{locoBean.strLocale}" />
</h:commandButton>
<h:commandButton value="de_DE">
<f:setPropertyActionListener value="#{'de_DE'}" target="#{locoBean.strLocale}" />
</h:commandButton>
</h:form>
</h:body>
</f:view>
</html>
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web.bean;
import java.util.Locale;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import web.utils.Utils;
/**
*
* @author Enira
*/
@ManagedBean
@SessionScoped
public class LocoBean {
private Locale locale;
private String strLocale;
public LocoBean() {
this.locale = new Locale("de", "DE");
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public String getStrLocale() {
return strLocale;
}
public void setStrLocale(String strLocale) {
try {
String[] loc = strLocale.split("_");
this.locale = new Locale(loc[0], loc[1]);
} catch (Exception e) {
this.locale = new Locale("en", "US");
}
this.strLocale = strLocale;
}
}