I have a JSF 2 composite component that employs some Ajax behavior. I want to add a listener
method to the <f:ajax>
tag inside my composite component, but the listener
method should be provided as a <composite:attribute>
in the <composite:interface>
.
The <f:ajax>
tag inside my composite component is currently hard-coded to a listener like this:
<f:ajax
event="valueChange"
execute="@this"
listener="#{controller.genericAjaxEventLogger}"
render="#{cc.attrs.ajaxRenderTargets}" />
The listener method on the bean has this signature:
public void genericAjaxEventLogger(AjaxBehaviorEvent event)
throws AbortProcessingException {
// implementation code...
}
I want the composite component to be something like this so the page can supply its own event method, but I can't figure out the correct syntax for the interface.
<f:ajax
event="valueChange"
execute="@this"
listener="#{cc.attrs.ajaxEventListener}"
render="#{cc.attrs.ajaxRenderTargets}" />
How can I do this?
UPDATED WITH SOLUTION:
I took the approach suggested by BalusC and it works great. The relevant snippets are:
The interface declaration in the composite component
<composite:interface>
<composite:attribute
name="myattributeUpdatedEventListener"
method-signature="void listener()"
required="true" />
...
</composite:interface>
The Ajax tag used in my composite component
<f:ajax
event="valueChange"
execute="@this"
listener="#{cc.attrs.myattributeUpdatedEventListener}"
render="#{cc.attrs.ajaxRenderTargets}" />
The place in my page where I use the composite component
<h:form>
<compcomp:myCompositeComponent
myattributeUpdatedEventListener="#{myBackingBean.updatedEventListenerXYZ}" />
</h:form>
And the method on my backing bean
public void updatedEventListenerXYZ() {
// do something here...
}