JSF el 未解析
我在 JSF 页面中有以下行:
<h:commandLink action="#{myBean.test}" value="Wizard Step"></h:commandLink>
我希望加载页面时,对应于 myBean 的 Bean 将被实例化(并且我将能够在 eclipse 调试器中看到这一点)。
JSF 的其余部分工作正常,但该 bean 无法解析(没有任何错误)。
如何从 el 无法解析 bean 中获取错误?
I have the following line in a JSF page:
<h:commandLink action="#{myBean.test}" value="Wizard Step"></h:commandLink>
I expect that when the page is loaded, the Bean corresponding to myBean will be instantiated (and I'll be able to see this in the eclipse debugger).
The rest of the JSF is working correctly, but this bean is not resolving (without any error).
How do I get the errors from the el failing to resolve the bean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有 EL 错误,你肯定会得到
javax.el
包:ELException
:表示表达式求值期间可能出现的任何异常情况。MethodNotFoundException
:抛出当计算MethodExpression
时找不到方法时。PropertyNotFoundException
:抛出当评估ValueExpression
或MethodExpression
时找不到属性时。PropertyNotWritableException
:抛出在ValueExpression
上设置值时无法写入属性时。在您的情况下,托管 bean 不是根据初始请求构建的。这只能意味着该托管 bean 没有在视图的其他地方被引用。
action
属性中的 EL 仅在提交表单时评估。因此,只有在调用操作时才会构造 bean。作为测试,只需将#{myBean}
放置在视图中的某个位置即可。您将看到它是根据初始请求构建的。您的真正问题是命令按钮操作根本不被调用,因此根本不评估其操作属性中的 EL。该问题无法在 EL 方面进行调试或确定。按钮操作未被调用的可能原因有很多。您可以在这里找到它们: commandButton/commandLink/ajax action/listener 方法未调用或输入值未更新。初学者中最常见的原因是按钮位于重复组件(如
)内,其值未正确保存并在表单提交请求期间返回完全不同的值,或者组件或其组件之一具有rendered
属性,该属性未正确保留且默认为false
。If there are EL errors, you will surely get an exception of
javax.el
package:ELException
: Represents any of the exception conditions that can arise during expression evaluation.MethodNotFoundException
: Thrown when a method could not be found while evaluating aMethodExpression
.PropertyNotFoundException
: Thrown when a property could not be found while evaluating aValueExpression
orMethodExpression
.PropertyNotWritableException
: Thrown when a property could not be written to while setting the value on aValueExpression
.In your case, the managed bean is not constructed on initial request. This can only mean that the managed bean is not referenced elsewhere in the view. The EL in
action
attribute is only evaluated when the form is submitted. So the bean will only be constructed when the action is invoked. As a test, just put#{myBean}
somewhere in the view. You'll see that it get constructed on initial request.Your real problem is that command button action is simply not invoked, so the EL in its action attribute is simply not evaluated at all. The problem cannot be debugged nor nailed down in the EL side. There are a lot of possible causes for the button action not being invoked. You can find them all here: commandButton/commandLink/ajax action/listener method not invoked or input value not updated. The most common cause among starters is that the button is inside an repeating component like
<h:dataTable>
whose value is not properly preserved and returns a completely different value during the form submit request, or that the component or one of its components has arendered
attribute which is not properly preserved and defaults tofalse
.