- priority: 5 --> 7
- assigned_to: nobody --> jkuhnert
Tacos runs Javascript in a response in a different
order than the browser does when the page is first loaded.
Consider the reponse:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[ <!ENTITY nbsp ' '> ]>
<ajax-response>
<response type="element" id="someElement">
<script>...[1]...</script>
</response>
<response type="element" id="scriptblock">
<script>...[2]...comes from <body> element in
.script file...</script>
<script>...[3]...comes from <initialization>
element in .script file...</script>
</response>
<response type="element" id="jsincludes">
<script>...[4]...tacos.loadScriptFromUrl("...")</script>
</response>
</ajax-response>
Tacos.js will run [4], [1], [2], and finally [3].
However, when a page is first loaded by a browser, the
Javascript in an equivalent HTML page is run in the
order [4], [2], [1], and finally [3]. Therefore, a
component that expects [2] to have happened before its
<script> blocks are executed will not work.
A fix for this is to change
InjectAjaxComponentRenderWorker.java as follows: replace
buf.append(" prs.writeBodyScript(")
.append("ajaxRequest.getResponseBuilder().getScriptWriter(),
$2);\n");
buf.append(" prs.writeInitializationScript(")
.append("ajaxRequest.getResponseBuilder().getScriptWriter());\n");
with:
buf.append(" prs.writeBodyScript(")
.append("ajaxRequest.getResponseBuilder().getComponentWriter(\"preprocess\"),
$2);\n");
buf.append(" prs.writeInitializationScript(")
.append("ajaxRequest.getResponseBuilder().getComponentWriter(\"postprocess\"));\n");
The response will now be:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[ <!ENTITY nbsp ' '> ]>
<ajax-response>
<response type="element" id="someElement">
<script>...[1]...</script>
</response>
<response type="element" id="postprocess">
<script>...[3]...comes from <initialization>
element in .script file...</script>
</response>
<response type="element" id="preprocess">
<script>...[2]...comes from <body> element in
.script file...</script>
</response>
<response type="element" id="jsincludes">
<script>...[4]...tacos.loadScriptFromUrl("...")</script>
</response>
</ajax-response>
The javascript will now run in the order [4], [2], [1],
and finally [3], that is, in the same order as the
initial page load.
Marcel