我有一个f:loadBundle,它从我的类路径加载一个属性文件。
<f:loadBundle basename="com.xxx.ui.messages" var="msg" />稍后,我将尝试使用来自资源包的消息,语法如下:
<h:outputText value="test message: #{msg.does_not_exist} --"/>过去,JSF会打印出“未找到”消息,但现在它抛出了一个异常。规范是否改变了,或者这是正确的行为吗?
我使用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
(文字字符串?KEY?是从映射返回的,其中键是在映射中查找的键,而不是抛出的MissingResourceException )
编辑:即使删除JUEL也会出现同样的问题
发布于 2012-06-15 22:39:15
所以答案实际上就是盯着你的脸...道具@millimoose,让我走上正确的道路。
请注意,规范中这样写道:
文字字符串?键?是从映射返回的,其中MissingResourceException是在映射中查找的键,而不是抛出的键。
但我的堆栈跟踪显示:
javax.el.PropertyNotFoundException:/WEB-INF/xxx.xhtml @10,70 value=“测试消息:#{msg.does_not_exist} --":在类型java.util.PropertyResourceBundle上找不到属性'does_not_exist‘
啊哈,可能是个bug!
知道这个类是从tomcat/lib中提取出来的,我浏览到了它们的源代码和javadoc here。注意到"getValue()“上的抛出声明了吗?
这与规范here形成了鲜明的对比。
因此,我从tomcat/lib中删除了el-api,并将其替换为spec jar (here),问题解决了!
为什么Tomcat与规范如此不同,我无法理解...那些疯狂的阿帕奇人。
https://stackoverflow.com/questions/11039791
复制相似问题