如何添加服务器端在所有 ajax 响应中发送的内容,以便我可以添加自己的参数?
我已经扩展了 Richfaces JavaScriptA4J.AJAX.finishRequest
来触发自定义事件,我想从服务器向它传递参数:
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);
};
另一种看待它的方式是,什么响应服务器端对 A4J.AJAX.Submit 的调用以及如何围绕它包装自己的代码?
我的解决方案
根据 BalusC 的回答,这就是我最终放入主模板的内容:
<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>