-
Dec 9th, 2012, 11:12 AM
#21
package com.myapp.jsf.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
@ManagedBean
@SessionScoped
public class LocaleBean {
private Locale locale;
@PostConstruct
public void init() {
locale = FacesContext.getCurrentInstance().getExternalConte xt().getRequestLocale();
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public SelectItem[] getLocales() {
List<SelectItem> items = new ArrayList<SelectItem>();
Iterator<Locale> supportedLocales = FacesContext.getCurrentInstance().getApplication() .getSupportedLocales();
while (supportedLocales.hasNext()) {
Locale locale = supportedLocales.next();
items.add(new SelectItem(locale.toString(), locale.getDisplayName()));
}
return items.toArray(new SelectItem[] {});
}
public String getSelectedLocale() {
return getLocale().toString();
}
public void setSelectedLocale() {
setSelectedLocale(FacesContext.getCurrentInstance( ).getExternalContext().getRequestParameterMap().ge t("locale"));
}
public void setSelectedLocale(String localeString) {
Iterator<Locale> supportedLocales = FacesContext.getCurrentInstance().getApplication() .getSupportedLocales();
while (supportedLocales.hasNext()) {
Locale locale = supportedLocales.next();
if (locale.toString().equals(localeString)) {
this.locale = locale;
break;
}
}
}
}
-
Dec 9th, 2012, 11:35 AM
#22
This is a web server version problem.
If you use Tomcat 7.x it should work without problems. You're already done
-
Dec 9th, 2012, 03:59 PM
#23
if i instead use jetty:run (since i think i am using tomcat 7) i get this:
Problem accessing /myapp/pages/main.jsf. Reason:
Target Unreachable, identifier 'bookBean' resolved to null
Caused by:
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bookBean' resolved to null
this has taken waaaaay too much time at this point. i thought this was supposed to be RAD out-of-the-box. i'm going to try groovy and see how much luck i have there.
-
Dec 15th, 2012, 11:26 AM
#24
so i switched to tomcat7 :
Dec 15, 2012 11:19:35 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
but still i get the locale bean error:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/thedrvault] threw exception [/templates/layout.xhtml at line 8 and column 63 locale="#{localeBean.locale}" Attribute did not evaluate to a String or Locale: null] with root cause
javax.faces.view.facelets.TagAttributeException: /templates/layout.xhtml at line 8 and column 63 locale="#{localeBean.locale}" Attribute did not evaluate to a String or Locale: null
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules