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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read Properties file Dynamically

 
Greenhorn
Posts: 2
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Duplicate. Locked.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic