无法找到资源包消息

时间:2013-12-17 05:57:49

标签: java jsf

这个问题非常相似(如果不一样):

"Can't find bundle for base name messages" error

ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages

基本上,我有这段代码:

<body>
<f:view>
<f:loadBundle basename="de.vogella.jsf.starter.messages" var="msg" />
<h:form>
<h:panelGrid columns="2">
  <h:outputLabel value="#{msg.user}"></h:outputLabel>
  <h:inputText value="#{user.name}">
  <f:validator
      validatorId="de.vogella.jsf.starter.validator.LoginValidator" />
  </h:inputText>
  <h:outputLabel value="#{msg.password}"></h:outputLabel>
  <h:inputSecret value="#{user.password}">
  </h:inputSecret>
</h:panelGrid>
<h:commandButton action="#{user.login}" value="#{msg.login}"></h:commandButton>
<h:messages layout="table"></h:messages>
</h:form>
</f:view>

当我尝试跑步时,我得到了

An exception occurred processing JSP page /LoginView.jsp at line 13 
10: </head> 
11: <body> 
12: <f:view> 
13: <f:loadBundle basename="de.vogella.jsf.starter.messages" var="msg" /> 
14: <h:form> 
15: <h:panelGrid columns="2"> 
16: <h:outputLabel value="#{msg.user}"></h:outputLabel> Stacktrace:

Caused by:
java.util.MissingResourceException - Can't find bundle for base name  de.vogella.jsf.starter.messages, locale en`

我尝试更改文件名,更改代码中的文件名,添加资源文件夹(但我认为已经正确包含),并将messages.properties文件放在所有可能的文件夹中。奇怪的是,eclipse本身显示了这个错误,它还有一个空的基本名称框(没有默认提议)。 如果它有帮助,我的项目结构: http://imgur.com/3eAxWo3

2 个答案:

答案 0 :(得分:2)

您能否确认目录de.vogella.jsf.starter中是否有message.properties文件? 如果没有,请在此目录中添加message.properties,然后编译所有。检查你是否仍然得到例外?

答案 1 :(得分:0)

我也遇到了同样的问题。 但最后,如果将messages.properties文件保存在任何包(de.vogella.jsf.starter.model)下并包含如下内容: &LT; f:loadBundle basename =&#34; de.vogella.jsf.starter.model.messages&#34; VAR =&#34; MSG&#34; /&GT; 这是工作。

相关问题