I would like to write my own CustomBehaviorHandler to make it behave as I need. The question is: how to register this new CustomBehaviorHandler with JSF?
You'd need to create a custom tag for that. Prepare a *.taglib.xml
as demonstrated in this answer: Custom Facelet component in JSF (note: taghandler class is not necessary) and add the following entry:
<tag>
<tag-name>ajax</tag-name>
<behavior>
<behavior-id>com.example.MyAjaxBehavior</behavior-id>
<handler-class>com.example.MyAjaxBehaviorHandler</handler-class>
</behavior>
<!-- Define attributes here. -->
</tag>
Then you'll be able to use <my:ajax>
. Note: you've got to reimplement a lot in the behavior handler class; you can't simply extend from BehaviorHandler
as it throws the exception during its construction already.
Or is there any other way to suit my needs?
Depends on concrete functional requirement for which you thought that this would be the solution. This is unfortunately not stated anywhere in the question, so I can't answer that part.
I can't find any example nor documentation about it, but it seems to be possible, since PrimeFaces has its own org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.
That's the <p:ajax>
. The <a4j:ajax>
which you've initially at your hands is also such one, by the way.