28

条件演算子は、「レンダリングされた」「値」などの多くの属性で機能します。

しかし、それは実際には機能しませんか?それとも私はそれを間違っていますか?

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

エラー:javax.el.E​​LException:有効なメソッド式ではありません

(primefaces ajaxアクション属性を使用して実現しました)

4

1 に答える 1

51

これはサポートされていません。action属性はであるはずですが、MethodExpression条件演算子はそれをValueExpression構文にします。MethodExpressionELのsではこれがサポートされることはないと思います。

基本的に2つのオプションがあります。

  1. ジョブを委任するシングルアクションメソッドを作成します。

    <h:commandButton ... action="#{bean.method}" />
    

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

    必要に応じて、メソッド引数として。で渡します#{bean.method(condition)}

  2. または、条件付きで2つのボタンをレンダリングします。

    <h:commandButton ... action="#{bean.methodTrue}" rendered="#{bean.condition}" />
    <h:commandButton ... action="#{bean.methodFalse}" rendered="#{not bean.conditon}" />
    
于 2012-05-28T19:46:33.777 に答える