2

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?

Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42
Antonio Laguna
  • 8,973
  • 7
  • 36
  • 72

1 Answers1

4

Actually the loadBundle component was made transient from JSF 2.0.

Source Code JSF 1.2

Source Code 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>
Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42
  • We load a MessageBundle for each language we have on the app. So, how could I load the `messageBundleSinProp` ? That one is replaced in runtime with whichever bundle needs to be loaded. – Antonio Laguna Jul 17 '12 at 10:29
  • @Antonio How are you specifying which bundle to load is it via a system property? – Ravi Kadaboina Jul 17 '12 at 14:38
  • really is a getter from the class `IdomaBean` which basically does: `getMessageBundle().substring(0,getMessageBundle().indexOf("."))`. The MessageBundle is selected at Login, depending certain parameters such as Country code or browser headers. – Antonio Laguna Jul 18 '12 at 06:18