1

We have in our JSF 2.2 project a composite component used like this (the code has been simplified for clarity):

<!-- the page with the composite component inside -->
<my:component methodListener="#{myBean.myMethod}" />

<!-- the composite component -->
<cc:interface>
    <cc:attribute name="methodListener" required="true" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)" />
    ...
<cc:implementation>
    <h:commandLink>
        <f:ajax listener="#{cc.attrs.methodListener}" />
        <f:attribute name="myAttribute" value="myValue" />
    </h:commandLink>
// the called method
public void myMethod(AjaxBehaviorEvent event)
{
    System.out.println("> " + event);
}

In Wildfly 9.0.2, when clicking on the commandLink inside the composite component, myMethod is called and the event is defined (allowing us to find back myAttribute value).

In Wildfly 10.1.0, with the exact same code, myMethod is called but the event parameter is always null.

Are we doing something wrong here?

A tested workaround could be to replace the methodListener CC attribute with a bean instance, something like the following code. Still, this would require a lot of replacements in our project, therefore we'd like to avoid this solution.

<!-- the workaround composite component -->
<cc:interface>
    <cc:attribute name="methodBean" required="true" type="com.example.myBean" />
...
<cc:implementation>
    <h:commandLink>
        <f:ajax listener="#{cc.attrs.methodBean.myMethod}" />
        <f:attribute name="myAttribute" value="myValue" />
    </h:commandLink>
Xavier Portebois
  • 3,354
  • 6
  • 33
  • 53

1 Answers1

0

Well, I didn't see this answer from BalusC on another related question. I still don't understand why my code worked on WF9 and broke on WF10, but here's a simple solution, where we don't have to change anything but the component itself:

<!-- the CC xhtml -->
<h:commandLink>
    <f:ajax listener="#{cc.methodListener}" />
    <f:attribute name="myAttribute" value="myValue" />
</h:commandLink>
// the CC implementation
public void methodListener(AjaxBehaviorEvent event)
{
    FacesContext context = getCurrentInstance();
    MethodExpression ajaxEventListener = (MethodExpression) getAttributes().get("methodListener");
    ajaxEventListener.invoke(context.getELContext(), new Object[] { event });
}
Community
  • 1
  • 1
Xavier Portebois
  • 3,354
  • 6
  • 33
  • 53