gpt4 book ai didi

jsf - 是否可以在 Action 属性中使用 EL 条件运算符?

转载 作者:行者123 更新时间:2023-12-03 10:35:30 24 4
gpt4 key购买 nike

条件运算符适用于许多属性,例如“渲染”“值”等。

但它在行动中不起作用?还是我做错了?

<h:commandLink action="#{true ? bean.methodTrue() : bean.methodFalse()}"/>

错误:javax.el.E​​LException:不是有效的方法表达式

(我使用 primefaces ajax Action 属性实现了它)

最佳答案

这是不支持的。 action属性应该是 MethodExpression , 但条件运算符使它成为 ValueExpression句法。我认为 MethodExpression 永远不会支持此功能s 在 EL。

你基本上有2个选择:

  • 创建一个委托(delegate)作业的单个操作方法。
    <h:commandButton ... action="#{bean.method}" />


    public String method() {
    return condition ? methodTrue() : methodFalse();
    }

    如有必要,通过 #{bean.method(condition)} 将其作为方法参数传入.
  • 或者,有条件地渲染 2 个按钮。
    <h:commandButton ... action="#{bean.methodTrue}" rendered="#{bean.condition}" />
    <h:commandButton ... action="#{bean.methodFalse}" rendered="#{not bean.conditon}" />
  • 关于jsf - 是否可以在 Action 属性中使用 EL 条件运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10473743/

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