我有一个 f:loadBundle,它从我的类路径加载属性文件。
<f:loadBundle basename="com.xxx.ui.messages" var="msg" />
稍后,我尝试使用来自资源包的消息,语法如下:
<h:outputText value="test message: #{msg.does_not_exist} --"/>
以前 JSF 会打印出“NOT FOUND”消息,但现在它会抛出异常。规范是否发生变化或者这是正确的行为吗?
我使用 Mojarra 2.1.9 和 JUEL 2.2.4 作为 EL 解析器。这是堆栈跟踪:
javax.el.PropertyNotFoundException: /WEB-INF/xxx.xhtml @10,70 value="test message: #{msg.does_not_exist} --": Property 'does_not_exist' not found on type java.util.PropertyResourceBundle
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
编辑: 可以在此处验证正确的行为:http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/loadBundle.html
(这表示从 Map 返回文字字符串 ???KEY???,其中 KEY 是在 Map 中查找的键,而不是抛出 MissingResourceException)
编辑:即使删除 JUEL 后也出现同样的问题
最佳答案
所以答案实际上就在你面前......感谢@millimoose 让我开始走上正确的道路。
请注意规范是这样说的:
the literal string ???KEY??? is returned from the Map, where KEY is the key being looked up in the Map, instead of a MissingResourceException being thrown.
但是我的堆栈跟踪是这样说的:
javax.el.PropertyNotFoundException: /WEB-INF/xxx.xhtml @10,70 value="test message: #{msg.does_not_exist} --": Property 'does_not_exist' not found on type java.util.PropertyResourceBundle
啊哈,可能是一个错误!
知道这个类将从 tomcat/lib 中提取,我浏览了它们的源代码和 javadoc here 。注意到“getValue()”上的 throws 声明了吗?
这与规范 here 形成鲜明对比.
所以我从 tomcat/lib 中删除了 el-api 并将其替换为规范 jar ( here ) 并解决了问题!
为什么 Tomcat 与规范如此不同,我无法理解......那些疯狂的 Apache 家伙。
关于使用 f :loadBundle. 时出现 javax.el.PropertyNotFoundException .. 这是否正确实现了规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039791/