I'm implementing the Serializable on all my session classes so I could make some farm clustering with a load balancer.
I already have the clustering under control and it's working fine. However, I'm getting an error which it seems I'm not able to solve.
Whenever I enter on the index.jsp I receive this error:
Mensaje: javax.servlet.ServletException: java.lang.Exception: javax.faces.FacesException: Problem in renderResponse: /WEB-INF/inc-content/content.jspx @5,73 <f:loadBundle basename="#{idioma.messageBundleSinProp}"> /WEB-INF/inc-content/content.jspx @5,73 basename="#{idioma.messageBundleSinProp}" setAttribute: Atributo no serializable
Tipo Error: class javax.servlet.ServletException
Excepcion: javax.servlet.ServletException: java.lang.Exception: javax.faces.FacesException: Problem in renderResponse: /WEB-INF/inc-content/content.jspx @5,73 <f:loadBundle basename="#{idioma.messageBundleSinProp}"> /WEB-INF/inc-content/content.jspx @5,73 basename="#{idioma.messageBundleSinProp}" setAttribute: Atributo no serializable
Codigo de Estado: 500
Nombre Servlet: jsp
Despite the Spanish, it basically says that the attribute isn't serializable. It seems I'm missing something because the idioma.messageBundleSinProp
is a getter, not a setter:
public String getMessageBundle()
{
if(idiomaSeleccionado!=null)
return(webUtil.getPropertiesValue(idiomaSeleccionado, "LanguageChances.properties"));
else
return(webUtil.getPropertiesValue(idiomaSeleccionadoDefecto, "LanguageChances.properties"));
}
public String getMessageBundleSinProp()
{
//String propertieSeleccionado=getMessageBundle();
return(getMessageBundle().substring(0,getMessageBundle().indexOf(".")));
}
What could be wrong?
Actually the loadBundle component was made transient from JSF 2.0.
Since you are also not using Icefaces 2.0. You cannot make use of this either. ICEFACES JIRA
So the only way I can think of is creating your own messageBean and retriving the messages.
You can do something like this:
public class MessageBean implements Serializable
{
transient private static ResourceBundle bundle;
transient private static Map map;
protected static ClassLoader getCurrentClassLoader(Object defaultObject)
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
{
loader = defaultObject.getClass().getClassLoader();
}
return loader;
}
MessageBean()
{
bundle = ResourceBundle.getBundle("LanguageChances", java.util.Locale.getDefault(), getCurrentClassLoader(null));
map = new HashMap<String, Object>();
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
Object value = bundle.getObject(key);
map.put(key, value);
}
}
public Map getMap(){
return map;
}
}
And use something like this on your page to retrieve the messages:
<c:forEach items="#{messageBean.map}" var="entry">
<h:outputText value="#{entry.key}"/>
</c:forEach>