3

I need to set a boolean field whenever p:fieldset is toggled. I tried out following code but the field is never set by f:setPropertyActionListener although p:ajax listener is invoked on toggle. I tried out following code.

    <p:fieldset legend="(Optional) Link.." toggleable="true">
        <p:ajax event="toggle" listener="..">
            <f:setPropertyActionListener target="#{viewScope.rendrUsrProjctsList}" value="#{true}"/>
        </p:ajax>
    </p:fieldset>

However when I tried modifying the code as below then field is successfully set:

    <p:fieldset legend="(Optional) Link.." toggleable="true">
        <p:ajax event="toggle" listener="#{view.viewMap.put('rendrUsrProjctsList', true)}" />
        <p:ajax event="toggle" listener=".."/>
        </p:ajax>
    </p:fieldset>

I want to ask:

  1. Why 1st way doesn't work ?
  2. Is it bad attaching multiple p:ajax to single parent as done in 2nd way ?
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294

1 Answers1

9

The <f:setPropertyActionListener> works as being an ActionListener implementation only on components implementing ActionSource interface, such as UICommand, i.e. <h:commandXxx>, <p:commandXxx>, etc. The <p:ajax> does not implement this interface and therefore the <f:setPropertyActionListener> is basically completely ignored.

As to your workaround, you could do so although I'd rather just use a concrete view scoped bean or wrap it in a composite with a backing component.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi BalisC, that's great, but its not mentioned on the OracleDocs http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/f/setPropertyActionListener.html – Kishor Prakash Feb 04 '16 at 10:13
  • @KishorP: I quote from your link: *"... registers it on the ActionSource associated with our most immediate surrounding instance..."* See also 1st link in my answer (it already points to that resource). – BalusC Feb 04 '16 at 10:16
  • Thanks very much BalusC :) – Kishor Prakash Feb 04 '16 at 12:39