gpt4 book ai didi

jsf - 评估是否设置了 MethodExpression 属性(获取 PropertyNotFoundException)

转载 作者:行者123 更新时间:2023-12-04 14:14:00 25 4
gpt4 key购买 nike

我有一个带有 MethodExpression 属性的 UI 组件 changeListener :

<composite:interface>
<composite:attribute name="changeListener" required="false" method-signature="void actionListener(javax.faces.event.ActionEvent)" />
..
</composite:interface>
<composite:implementation>

<p:remoteCommand name="ajaxOnChange"
update="#{cc.attrs.onChangeUpdate}"
oncomplete="#{cc.attrs.onchange}"
actionListener="#{cc.attrs.changeListener}" />
..
</composite:implementation>

changeListener属性是一个可选的方法表达式,用作 Action 监听器remoteCommand我想渲染 <p:remoteCommand>仅当 changeListener属性已设置。

我尝试了几种方法来检查是否设置了属性,尤其是:

<c:if test="#{! empty cc.attrs.changeListener}">



<p:remoteCommand rendered="#{cc.attrs.changeListener != null}" />

但是我得到一个 javax.el.PropertyNotFoundException 因为它试图将属性评估为属性。

如何评估是否设置了可选方法属性?

谢谢

最佳答案

你的方向是正确的 <c:if>已经。 rendered一个永远不会工作。您只需要检查 EL expression 是否被设置而不是实际将整个 EL 表达式评估为值表达式并检查其结果是否为空,如果 EL 表达式表示方法表达式,这当然会失败。

<c:if test="#{not empty cc.getValueExpression('changeListener')}">
...
</c:if>

然而,这个解决方案有点可怕:您在这里将方法表达式作为值表达式抓取。但是,只要您不实际评估封闭的 EL 表达式(就像您最初的 #{cc.attrs.changeListener} 尝试在幕后所做的那样),那么就没有任何关系。没有其他干净的方法,因为没有像 UIComponent#getMethodExpression() 这样的东西在 JSF API 中。

关于jsf - 评估是否设置了 MethodExpression 属性(获取 PropertyNotFoundException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com