javax.servlet.ServletException:无法找到基本名称消息,区域设置的包

时间:2013-04-30 22:32:36

标签: jsf primefaces

有时我会收到错误:

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

我有一个带有primefaces的JSF应用程序,其中捆绑消息几乎总是正常工作,除了xhtml中的一个案例,单击按钮保存数据,有时可以工作,有时不工作,具体取决于什么图像包含或不包含对象p:编辑器。当它因以下错误而失败时,好像没有找到消息:

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)

虽然它可能是bounle帖子的配置,因为它几乎总是像我一样离开这里:

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错误:

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

MessageResources.properties文件,src目录。

提前致谢,以防万一有人发生类似事情。

1 个答案:

答案 0 :(得分:1)

您收到的错误是指<message-bundle>中的faces-config.xml,而不是您所期望的<resource-bundle><f:loadBundle>

首先,请仔细阅读以下答案,了解差异:Internationalization in JSF, when to use message-bundle and resource-bundle?

因此,消息包适用于JSF自己的标准转换器/验证器,例如<f:convertDateTime>required="true"<f:validateLength>等,资源包适用于您自己的i18n文本内容,例如标题,段落,标签,工具提示等。请注意LengthValidator调用UIInput#validate()期间ProcessValidationsPhase在堆栈跟踪中的参与情况。这应该已经给出了一些关于真正问题的提示。

相应地修复/对齐它。也许你只需要完全摆脱<message-bundle>并依赖JSF默认转换/验证消息。