You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Carlos Pita <ca...@gmail.com> on 2008/11/13 22:49:23 UTC

renderJavascript with null id during ajax request

Hi,

I've observed a behavior which I'm not sure is intentional or a bug.

The fact is that when contributing to the header during an ajax
response with response.renderJavascript(myScript, null), the branch
for eval(myScript) in wicket-ajax.js/processScript is taken (because
of the null id in the script tag, of course). Here is an excerpt of
the code:


                if (typeof(id) == "string" && id.length > 0) {
                    // add javascript to document head
                    Wicket.Head.addJavascript(text, id);
                } else {
                    try {
                        eval(text);
                    } catch (e) {
                        Wicket.Log.error(e);
                    }
                }

Well, the eval doesn't seem to happen at the window context, so if
myScript is defining new support functions they're not seen by the
rest of the page. I've debugged this from the firebug stepper, and in
fact definitions in myScript take effect immediately after the eval,
while flow of execution remains at processScript, but vanish once this
function ends its execution.

If instead an id is given to renderJavascript the history is another
and the functions defined by myScript exist at the window scope,
because they are included as usual as script tags under the head.

As I understand it the point of the id argument is to avoid duplicate
definitions or in general executions of javascript code fragments. So
the difference in scoping semantics looks like a bug, because it has
nothing to do with the aforementioned intention. Anyway, is this
expected or should I file an issue at the tracker?

Best regards
-Carlos

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org