Saturday, 7 September 2013

selectonemenu and internalization does not work properly

selectonemenu and internalization does not work properly

When I change my internalization selectonemenu, the values in my other 2
selectonemenus do not change. I use internalization menu per this
http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/,
and the following code for the other two.
my bean
private Locale locale =
FacesContext.getCurrentInstance().getViewRoot().getLocale();
@PostConstruct
public void init() {
showCountries();
}
public void showCountries() {
DAOFactory javabase = DAOFactory.getInstance("javabase.jdbc");
CountryDAO countryDAO = javabase.getCountryDAO();
System.out.println("Country is "+locale.getLanguage());
countries = countryDAO.list(locale.getLanguage())
}
public void loadStates() {
try {
showStates();
getCountry();
} catch (SQLException | NamingException ex) {
Logger.getLogger(FormRegister.class.getName()).log(Level.SEVERE,
null, ex);
}
}
public void showStates() throws SQLException, NamingException {
switch (locale.getLanguage()) {
case "en":
stateDB = "state_name";
break;
case "bg":
stateDB = "state_name_bg";
break;
}
System.out.println("State is " + language);
states = new ArrayList<>();
switch (country) {
case "BGR": {
break;
}
case "USA": {
break;
}
default: {
country = "NONE";
break;
}
}
Connection conn = Database.createConn();
String sql = "SELECT id_state," + stateDB + " FROM chef_states WHERE
state_country='" + country + "' ORDER BY " + stateDB;
Statement st = conn.createStatement();
ResultSet result = st.executeQuery(sql);
while (result.next()) {
states.add(new
SelectItem(result.getString("id_state"),result.getString(stateDB)));
}
conn.close();
}
my view:
<h:selectOneMenu id="country" value="#{account.country}" required="true"
requiredMessage="#{msg['register.required']}" binding="#{country}">
<f:selectItem itemValue="#{null}"
itemLabel="#{msg['register.countryQ']}"/>
<f:selectItems itemValue="#{co.countryCode}"
itemLabel="#{co.countryName}" value="#{account.countries}" var="co"/>
<f:ajax listener="#{account.loadStates()}" render="state"/>
</h:selectOneMenu>
<h:selectOneMenu id="state" required="true"
requiredMessage="#{msg['register.required']}" value="#{account.state}" >
<f:selectItem itemValue="#{null}"
itemLabel="#{msg['register.countryQ']}"/>
<f:selectItems value="#{account.states}"/>
</h:selectOneMenu>

No comments:

Post a Comment