0
votes

Sometimes I get the error:

"javax.servlet.ServletException: Can not find bundle for messages based name, locale is"

I have a JSF application with primefaces where bundle messages, almost always working correctly except for one case in a xhtml, clicking a button one that saves data in a , sometimes works and sometimes not, depending on what images to include or not the object p: editor. When it fails with the following error, as if not to find the messages:

Estado HTTP 500 - Can't find bundle for base name messages, locale es

type Informe de Excepción

mensaje Can't find bundle for base name messages, locale es

descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.

excepción

javax.servlet.ServletException: Can't find bundle for base name messages, locale es
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
    uned.lsi.security.SecurityFilter.doFilter(SecurityFilter.java:62)

causa raíz

java.util.MissingResourceException: Can't find bundle for base name messages, locale es
    java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
    java.util.ResourceBundle.getBundleImpl(Unknown Source)
    java.util.ResourceBundle.getBundle(Unknown Source)
    javax.faces.validator.MessageFactory.getMessage(MessageFactory.java:155)
    javax.faces.validator.MessageFactory.getMessage(MessageFactory.java:245)
    javax.faces.validator.LengthValidator.validate(LengthValidator.java:228)
    javax.faces.component.UIInput.validateValue(UIInput.java:1142)
    javax.faces.component.UIInput.validate(UIInput.java:960)
    javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
    javax.faces.component.UIInput.processValidators(UIInput.java:693)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIForm.processValidators(UIForm.java:240)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    org.primefaces.component.panel.Panel.processValidators(Panel.java:293)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
    com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    uned.lsi.security.SecurityFilter.doFilter(SecurityFilter.java:62)

Although it may be the configuration of bounle posts, because it works almost always leave here as I have:

faces-config

 <application>
    <message-bundle> messages </ message-bundle>
     <locale-config>
        <default-locale> is </ default-locale>
     </ Locale-config>

    <resource-bundle>
      <base-name> MessageResources </ base-name>
      <var> msg </ var>
    </ Resource-bundle>
 </Application>

xhtml error:

<f:loadBundle basename="MessageResources" var="msg"/>

MessageResources.properties file, the src directory.

Thanks in advance, in case someone ever happened something similar.

1
in the default-locale you put 'is', is that a typo? are you only supporting spanish? Also you should specify full path for class MessageResources (with package names), example: com.myapp.language.MessageResources Also: do the language files have the .properties extension?damian

1 Answers

1
votes

The error you got is referring to the <message-bundle> in faces-config.xml, not to the <resource-bundle> nor the <f:loadBundle> which you seemed to expect.

First of all, please carefully go through the following answer to learn about the difference: Internationalization in JSF, when to use message-bundle and resource-bundle?

So, the message bundle is for JSF's own standard converters/validators such as <f:convertDateTime>, required="true", <f:validateLength>, etc and the resource bundle is for your own i18n text stuff such as headers, paragraphs, labels, tooltips, etc. Please note the involvement of LengthValidator in the stack trace during UIInput#validate() call of ProcessValidationsPhase. This should already have given some hints about the real problem.

Fix/align it accordingly. Perhaps you just need to get rid of <message-bundle> altogether and rely on JSF default conversion/validation messages.