Question

I have a following test composite component:

<composite:interface>
    <composite:clientBehavior event="click" targets="#{cc.clientId}:label"
        name="click" />
</composite:interface>

<composite:implementation>
    <h:outputLabel value="click here" id="label" style="background-color: red" />
</composite:implementation>

and when I use it attaching f:ajax client behavior my listener method is not called on server side, but POST request reaches the server. I noticed that when I don't specify f:ajax's execute attribute or specify it as "@this" listener is not called, but with execute="@form" or "@all" it works.

These examples don't work:

<h:form>
  <t:testComposite>
     <f:ajax event="click" listener="#{bean.test}" />
   </t:testComposite>
</h:form>

<h:form>
  <t:testComposite>
     <f:ajax event="click" listener="#{bean.test}" execute="@this"/>
   </t:testComposite>
</h:form>

These examples work:

<h:form>
  <t:testComposite>
     <f:ajax event="click" listener="#{bean.test}" execute="@form" />
   </t:testComposite>
</h:form>

<h:form>
  <t:testComposite>
     <f:ajax event="click" listener="#{bean.test}" execute="@all" />
   </t:testComposite>
</h:form>

<h:form id="form">
  <h:panelGroup id="group">
     <t:testComposite>
        <f:ajax event="click" listener="#{bean.test}" execute=":form:group" />
      </t:testComposite>
  </h:panelGroup>
</h:form>

I tested it on tomcat 7 with myfaces 2.1.12 and jboss as7 with mojarra 2.1.18.

My question is: why doesn't f:ajax work with execute="@this" when attached to a composite component?

Was it helpful?

Solution

The base of the targets is implicit, so targets="#{cc.clientId}:label" is not necessary. You should use targets="label" instead.

It is hard to explain, but the reason why targets="#{cc.clientId}:label" does not work is because the EL expression is calculated ouside the context or is evaluated before the component tree is built, so in this case for example, when it tries to derive the parent component, the child has not been attached to the view yet.

The general rule is don't call getClientId() when facelet is building the tree (inside a facelet TagHandler for example), and instead use a listener attached to PostAddToViewEvent for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top