标题真的说明了一切。我进行了一次尝试,但失败了,并显示以下错误:
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>这样做的正确方法是什么?
发布于 2011-06-15 19:18:03
这确实是行不通的。之后你不能像那样传递“额外的”参数。您声明的method-signature必须在使用复合组件的一端实现。例如。
<my:button action="#{bean.remove('Somestring')}" />复合组件实现应该如下所示
<h:commandButton value="Remove" action="#{cc.attrs.removeFieldAction}" />如果这不是您想要的,并且您确实想要从复合组件端传递它,那么我可以想到两种传递额外参数的方法:使用带有操作侦听器的将其作为属性组件属性传递,或者使用让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属性。
https://stackoverflow.com/questions/6355543
复制相似问题