2

I am trying to create a standardized button panel, that will show on most of our screens. Since the buttons will always be the same, except for some actions the signature of the composite component is this:

<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>

When I add this CC to my view like this:

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

The method zef0302View.save() is called directly and not passed to the CC. What am I doing wrong? I already passed methods as attributes to other components, but I cannot see what I did different.

I am using Wildfly 8.1 with JSF 2.2.

Thanks for the help.

[Edit]

The problem was not the passing of the attributes, but the test of their presence in the CC. Apparently when testing a method like this <c:if test="null ne cc.attrs.resetAction"/> that method gets called. The same is true for testing not empty cc.attrs.resetAction.

To properly test for the presence of the method attribute, without actually invoking it is <c:if test="cc.getValueExpression('actionMethod')"> (or put it in the rendered block wherever needed).

The solution came from another question Smutje was so kind to point my attention to (see comments).

Thelonius
  • 71
  • 2
  • 8
  • And `zef0302View.reset()` is not called directly? Then I would doubt it has anything to do with the parameters and rather with some other place the method gets called. – Smutje Aug 12 '14 at 21:08
  • 1
    @Smutje: OP is just treating it as a VE while comparing against `null`. – BalusC Aug 12 '14 at 21:11
  • @BalusC but inside of the ` – Smutje Aug 12 '14 at 21:14
  • 1
    @Smutje: apparently that method didn't do much interesting which caught OP's attention. The save method might have triggered a DB query or exception or what not which the OP could hardly miss. – BalusC Aug 12 '14 at 21:17
  • @Smutje: The save method threw a NullpointerException (unrelated to the problem at hand) and therefore the reset did not get called. If I don't pass the attribute saveAction, reset gets called as well. – Thelonius Aug 13 '14 at 04:49
  • @Smutje: But your second comment gave me the pointer. Apparently when testing a method in an `` that method gets called. Which leaves the question: How do I test for the presence of a method attribute, without calling it? I tried `` and `` both to no avail. – Thelonius Aug 13 '14 at 05:01
  • Check the accepted answer of http://stackoverflow.com/questions/15420081/jsf2-0-composite-component-with-optional-method-expression – Smutje Aug 13 '14 at 05:05

0 Answers0