これは実際には機能しません。そのように後で「追加の」パラメーターを渡すことはできません。あなたが宣言した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
属性を完全に省略することもできます。