将方法传递给复合组件直接执行该方法

时间:2014-08-12 21:02:42

标签: jsf el jsf-2.2 composite-component methodexpression

我正在尝试创建一个标准化的按钮面板,它将显示在我们的大多数屏幕上。由于按钮将始终相同,除了某些操作之外,复合组件的签名是:

<composite:interface>

<composite:attribute required="true" name="fallbackOutcomeOnClose" type="java.lang.String"/>
<composite:attribute name="saveAction" method-signature="void action()"/>
<composite:attribute name="resetAction" method-signature="void action()"/>
<composite:attribute default="@form" name="processOnSave" type="java.lang.String"/>

</composite:interface>

<composite:implementation>
<partials:navigationButton title="#{msg['common.close']}" fallbackOutcome="#{cc.attrs.fallbackOutcomeOnClose}"/>

<c:if test="#{null ne cc.attrs.saveAction}">
    <p:commandButton title="#{msg['common.save']}" value="#{msg['common.save']}"
                     action="#{cc.attrs.saveAction}"
                     styleClass="btn btn-primary pull-right"
                     process="@this #{cc.attrs.processOnSave}"
                     update="@all"/>
</c:if>
<c:if test="#{null ne cc.attrs.resetAction}">
    <partials:warningWithConfimButton title="msg['common.reset']" action="#{cc.attrs.resetAction}" type="reset" styleClass="pull-right"/>
</c:if>

当我将此CC添加到我的视图中时:

<partials:standardButtonPanel fallbackOutcomeOnClose="someview" resetAction="#{zef0302View.reset()}"
                              saveAction="#{zef0302View.save()}" processOnSave="zef0302_allg_det_id zef0302_periodika_id zef0302_indexierung_id"/>

直接调用方法zef0302View.save(),而不是传递给CC。我究竟做错了什么?我已经将方法作为属性传递给其他组件,但我看不出我做的不同。

我正在使用Wildfly 8.1和JSF 2.2。

感谢您的帮助。

[编辑]

问题不在于属性的传递,而在于它们在CC中的存在的测试。显然,在测试类似<c:if test="null ne cc.attrs.resetAction"/>的方法时,该方法会被调用。测试not empty cc.attrs.resetAction也是如此。

要正确测试方法属性的存在,而不实际调用它是<c:if test="cc.getValueExpression('actionMethod')">(或将其放在rendered块中的任何位置。

解决方案来自另一个问题Smutje非常友好地指出我的注意力(见评论)。

0 个答案:

没有答案