Olá
Tenho os seguintes arquivos de properties:
MessageResources_en_US.properties
MessageResources_en.properties
Nesse Formulário tenho as bandeiras do Brazil, Estados Unidos e Espanha, sempre que essa jsp é reenderizado
ele traz os texto do arquivo de properties: MessageResources_en.properties, agora gostaria que quando
o usuário click na bandeira do Estados Unidos ele reenderizasse o jsp com os texto que estão no arquivo
MessageResources_en_US.properties ou seja em ingles.
Segue meu BEAN e meu jsp e o faces-config.xml
Grato
//=====================================BEAN========================================
view plaincopy to clipboardprint?
package de.laliluna.tutorial.messageresource.bean;
import javax.faces.context.FacesContext;
import de.laliluna.tutorial.messageresource.utils.Utils;
import java.sql.Connection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.html.HtmlInputTextarea;
import javax.faces.component.html.HtmlOutputLabel;
import javax.faces.component.html.HtmlSelectBooleanCheckbox;
import javax.faces.component.html.HtmlSelectManyCheckbox;
import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.component.html.HtmlSelectOneRadio;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.richfaces.component.html.HtmlCalendar;
/**
* Backing Bean Class MyBean
*/
public class MyBean {
private HtmlInputText inputNome = new HtmlInputText();
private HtmlInputText inputSenha = new HtmlInputText();
public MyBean(){
System.out.println("entrei no contrutor MyBean");
}
public String getWelcomeMessage() {
FacesContext context = FacesContext.getCurrentInstance();
String text = Utils.getMessageResourceString(context.getApplication()
.getMessageBundle(), "welcome", null, context.getViewRoot()
.getLocale());
return text;
}
public HtmlInputText getInputNome() {
return inputNome;
}
public void setInputNome(HtmlInputText inputNome) {
this.inputNome = inputNome;
}
public HtmlInputText getInputSenha() {
return inputSenha;
}
public void setInputSenha(HtmlInputText inputSenha) {
this.inputSenha = inputSenha;
}
public String submitFormulario() {
return "cadastroCliente";
}
}
//=====================================JSP============================
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://myfaces.apache.org/sandbox"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
<ui:composition template="/templates/common.jsp">
<ui:define name="body">
<form jsfc="h:form" id="mainform">
<f:loadBundle basename="de.laliluna.tutorial.messageresource.MessageResources" var="msg"/>
<br></br><br></br>
<h:outputText value="#{msg.welcome}" />
<br></br><br></br>
<table>
<tr><td colspan="2"><h:outputText value="#{msg.language}" /></td></tr>
<tr><td><h:commandButton image="#{msg.imageBrazil}"></h:commandButton></td> <td><h:commandButton image="#{msg.imageUS}"></h:commandButton> </td> <td> <h:commandButton image="#{msg.imageSP}"></h:commandButton></td></tr>
</table>
<table>
<tr><td><h:outputText value="#{msg.user}" /></td> <td><h:inputText id="nome" binding="#{formulario.inputNome}"> </h:inputText></td></tr>
<tr><td><h:outputText value="#{msg.login}" /></td> <td><h:inputSecret id="senha" binding="#{formulario.inputSenha}"> </h:inputSecret></td></tr>
<tr><td colspan="2" align="center"><a4j:commandButton action="#{formulario.submitFormulario}" value="Submit"></a4j:commandButton></td></tr>
</table>
</form>
</ui:define>
</ui:composition>
</html>
========================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_1_2.xsd"
version="1.2">
<!-- Message Bundle -->
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>en_US</supported-locale>
<supported-locale>de</supported-locale>
</locale-config>
<message-bundle>
br.com.bicbanco.MessageResources
</message-bundle>
</application>
<managed-bean>
<managed-bean-name>formulario</managed-bean-name>
<managed-bean-class>de.laliluna.tutorial.messageresource.bean.MyBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/pages/page2.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>