Description

I have component with behavior which adds <script> element in Behavior.onComponentRendered() to respons. This javascript is to be processed in browser when component is rendered. This works pretty well when component is rendered during standard HTTP request. But when the same code is called from Ajax request, this script runs on browser two times!

There is some magic in Ajax request processing in wicket-ajax.js: only for Opera and IE these <script> elements from responses are added to HTML and page <header> element as well. Comment says that this is workaround for these browsers, maybe in older versions of Opera dynamically adding element into HTML doesn't run <script> elements within, but now could be obsolete.

Fix works only for components which has <script> element on its first level (as seen in first test case). When component with script behavior is added to another component (Panel e.g.) and this parent component is changed in AJAX request, script is executed twice in browser again. See my second test case.

I have tried this simple solution: in replaceOuterHtml() method in wicket-ajax.js comment out test for Opera browser, so in this case is executed same code as in Gecko browsers. It works for me in all of my real cases (pretty large application which heavily uses Wicket). It seems like modern Opera versions are more compatible with Gecko than older versions.

Martin Schayna
added a comment - 13/Jul/11 16:22 I'm afraid this ticket must be reopened.
Fix works only for components which has <script> element on its first level (as seen in first test case). When component with script behavior is added to another component (Panel e.g.) and this parent component is changed in AJAX request, script is executed twice in browser again. See my second test case.
I have tried this simple solution: in replaceOuterHtml() method in wicket-ajax.js comment out test for Opera browser, so in this case is executed same code as in Gecko browsers. It works for me in all of my real cases (pretty large application which heavily uses Wicket). It seems like modern Opera versions are more compatible with Gecko than older versions.
if (Wicket.Browser.isIE()) { //-- don't do this for Opera || Wicket.Browser.isOpera()) {
Wicket.replaceOuterHtmlIE(element, text);
} else if (Wicket.Browser.isSafari() ) {
Wicket.replaceOuterHtmlSafari(element, text);
} else /* GECKO */ {
...

We know that Opera 11 is not Opera 9. The same is valid for Safari 5 which is treated as Safari 3.
If we do your "fix" then some user of Opera 9/10 may complain that it doesn't work ...
We have plans to use JQuery for the functionality needed by wicket-ajax.js so hopefully this will solve all such issues. But this is planned for Wicket 1.6/1.7.

Martin Grigorov
added a comment - 13/Jul/11 16:28 Which second case you mean ?
We know that Opera 11 is not Opera 9. The same is valid for Safari 5 which is treated as Safari 3.
If we do your "fix" then some user of Opera 9/10 may complain that it doesn't work ...
We have plans to use JQuery for the functionality needed by wicket-ajax.js so hopefully this will solve all such issues. But this is planned for Wicket 1.6/1.7.

Martin Schayna
added a comment - 13/Jul/11 16:39 OK, I see that my simple "fix" doesn't work in Opeara 9, hm.
I upload second test case right now, it demonstrates where your first fix failed. I hope it should be resolved in Wicket 1.4. Thanks for your support.