• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to read Properties file Dynamically in JSF

 
Greenhorn
Posts: 2
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are trying to create Localization Example App In that according to user selection language has to change. I am giving my code here can any one help me in this

Language selection page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Select Language"></h:outputText>
<h:selectOneMenu id="dropdown" value="#{languageDetails.locale1}">
<f:selectItem itemValue="en" itemLabel="English" />
<f:selectItem itemValue="es" itemLabel="Spanish" />
<f:selectItem itemValue="fr" itemLabel="French" />
</h:selectOneMenu>
</h:panelGrid>
<p><h:commandButton id="change" value="Change Language"
action="#{languageDetails.changeLanguage}" /></p>
</h:form>

</f:view>
</body>
</html>


Here in this page i need to get language according to user selection

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view locale="#{languageDetails.locale2}">

<h:form>
<table>
<f:loadBundle var="msg" basename="com.bean.messages_en"/>

<h:panelGrid columns="2">
<tr><td><h:outputText value="#{msg.name}"></h:outputText></td>
<td><h:inputText value="#{userDetails.name}"></h:inputText></td></tr>
<tr><td><h:outputText value="#{msg.age}"></h:outputText></td>
<td><h:inputText value="#{userDetails.age}"></h:inputText></td></tr>
<tr><td><h:outputText value="#{msg.mail}"></h:outputText></td>
<td><h:inputText value="#{userDetails.email}"></h:inputText></td></tr>
<tr><td><h:outputText value="#{msg.dob}"></h:outputText></td>
<td><h:inputText id="dob1" value="#{userDetails.dob}">
<f:convertDateTime type="date" pattern="MM/dd/yyyy" />
<h:message for="dob1"></h:message>
</h:inputText></td></tr>
<tr><td><h:commandButton value="submit" action="submitted"/></td></tr>
</h:panelGrid>
</table>
</h:form>

</f:view>
</body>
</html>


faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
<managed-bean>
<managed-bean-name>languageDetails</managed-bean-name>
<managed-bean-class>com.bean.Language</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>


<navigation-rule>
<from-view-id>/Input.jsp</from-view-id>
<navigation-case>
<from-outcome>changed</from-outcome>
<to-view-id>/UserDetailsForm.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
<supported-locale>fr</supported-locale>
</locale-config>
<message-bundle>com.bean.messages_en</message-bundle>
<message-bundle>com.bean.messages_es</message-bundle>
<message-bundle>com.bean.messages_fr</message-bundle>
</application>
</faces-config>



We are using three propertie files. According to user selection particular propertie file has to load

Please can anyone help in this. Thanks in Advance.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your question? I don't see one?
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hazarding a guess, you need to look at f:view locale="#{bean.language}" where the language property is
something like "en", "es" or "fr" and you have files like messages_fr.properties and these are supported-locale's
in faces-config.

The bean should be session scoped and you also need to change the locale in the view when the user selects
a new language:



Also it's recommended to use h:selectOneMenu onchange="submit()" to synchronously refresh the page.
 
Saloon Keeper
Posts: 28831
212
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do not post the same question more than once. It confuses people. I'm going to lock the other copy.
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic