How can I add server side what is sent in all ajax responses so that I can add my own parameters?
I have extended richfaces JavaScript A4J.AJAX.finishRequest
to trigger a custom event and I would like to pass parameters to it from the server:
var originalFinishRequest = A4J.AJAX.finishRequest;
A4J.AJAX.finishRequest = function(request) {
var parameters = request.options.parameters;
if (!request._oncomplete_aborted) {
jQuery(document).trigger('onAutofocus',parameters);
}
originalFinishRequest(request);
};
Another way of looking at it would be, what responds server side to calls to A4J.AJAX.Submit and how do I wrap my own code around that?
My solution
This is what I ended up putting in my master template, based on BalusC's answer:
<a4j:outputPanel ajaxRendered="true">
<c:if test="#{not empty flowScope.autofocusSelectors}">
<script>
document.autofocusSelectors = #{flowScope.autofocusSelectors};
console.log("BASE TEMPLATE: autofocus: (#{flowScope.autofocusSelectors})");
</script>
</c:if>
<script>
console.log("BASE TEMPLATE AJAX RENDER")
//NB: autofocusSelectors not always set, and not only reason to autofocus
jQuery(document).trigger('onAutofocus');
</script>
</a4j:outputPanel>