15

タイトルは本当にそれをすべて言います。私はエラーで失敗した試みをしました:

Illegal attempt to pass arguments to a composite component lookup expression (i.e. cc.attrs.[identifier]).

私の試みは次のようになります。

<composite:interface>
  <composite:attribute name="removeFieldAction" method-signature="void action(java.lang.String)" />
</composite:interface>
<composite:implementation>
  <h:commandButton value="Remove" action="#{cc.attrs.removeFieldAction('SomeString')}"/>
</composite:implementation>

これを行う正しい方法は何ですか?

4

1 に答える 1

36

これは実際には機能しません。そのように後で「追加の」パラメーターを渡すことはできません。あなたが宣言したmethod-signatureように、複合コンポーネントが使用されている側で満たされる必要があります。例えば

<my:button action="#{bean.remove('Somestring')}" />

複合コンポーネントの実装は次のようになります

<h:commandButton value="Remove" action="#{cc.attrs.removeFieldAction}" />

これがあなたが望むものではなく、本当に複合コンポーネント側からそれを渡したい場合は、追加の引数を渡す 2 つの方法を考えることができます<f:attribute><f:setPropertyActionListner>JSF は、アクションが呼び出される直前にプロパティとして設定します。しかし、どちらも複合コンポーネントに変更がないわけではありません。複合コンポーネントの属性として、少なくとも Bean 全体を要求する必要があります。

を使用した例を次に示し<f:setPropertyActionListener>ます。これにより、アクションが呼び出される直前にプロパティが設定されます。

<composite:interface>
    <composite:attribute name="bean" type="java.lang.Object" />
    <composite:attribute name="action" type="java.lang.String" />
    <composite:attribute name="property" type="java.lang.String" />
</composite:interface>
<composite:implementation>
    <h:commandButton value="Remove" action="#{cc.attrs.bean[cc.attrs.action]}">
        <f:setPropertyActionListener target="#{cc.attrs.bean[cc.attrs.property]}" value="Somestring" />
    </h:commandButton>
</composite:implementation>

として使用される

<my:button bean="#{bean}" action="removeFieldAction" property="someString" />

上記の例では、Bean は次のようになります。

public class Bean {

    private String someString;

    public void removeFieldAction() {
        System.out.println(someString); // Somestring
        // ...
    }

    // ...
}

特定の規則に従う場合は、property属性を完全に省略することもできます。

于 2011-06-15T11:18:03.453 に答える