4 Replies Latest reply on Nov 12, 2012 7:17 AM by Renjith Jose

    firefox 11 and richfaces 3.1.5.GA/jsf 1.1.11 html injection

    J D Newbie

      So we have a jsf/myfaces + rf app that works fine with FF 10. But FF 11 came out this week and we saw an issue with html injection from a4j tags.  If we have a simple facelet page, and add just a single a4j component, firefox 11 will render TWO head and body tags - the extra body tag is just empty - and they are rendered in somewhat random order, sometimes the empty body tag is after our page content, sometimes before.  The extra head tag contains

      <head><script xmlns="http://www.w3.org/1999/xhtml">A4J.AJAX._scriptEvaluated=true;</script></head>

       

      This throws off a lot of our complex css and jquery logic on the client side (we have a css/js developer who is playing around with some hacky ways around it but that's not ideal).  Are other people seeing this or have any idea of a workaround so a4j tags do not auto-inject extra head/body tags? 

       

      I've heard that jsf2/richfaces 4 does not have this issue but upgrading would take a lot of time and effort at this point so wanted to see if there were any other options (and I guess also to confirm it is indeed the case that rf4 doesn't have this issue with FF 11 if we do have to end up upgrading).  Thanks!

        • 1. Re: firefox 11 and richfaces 3.1.5.GA/jsf 1.1.11 html injection
          Jhonata Amaral Newbie

          Hi,

          I have the same problem, I had this problem only with the Google Chrome, but now this happens with FF also.

          Could you show how to solve the problem with jquery?

           

          thanks.

          • 2. Re: firefox 11 and richfaces 3.1.5.GA/jsf 1.1.11 html injection
            Jean Blanchard Newbie

            Hi

            I've had this issue for a while, since I use Firefox nightly builds.

             

            The issue is actually caused by Firefox starting to support the "outerHtml" DOM property, so the "A4J.AJAX._scriptEvaluated" code is inserted using the fallback IE-targetting code instead of the code targetting modern browsers.

             

            To fix it you would have to update the file /org/ajax4jsf/javascript/scripts/AJAX.js from richfaces-impl.jar.

             

            Unfortunately, I don't have access to the library, so here is the ugly workaround I'm using :

             

                     &lt;!--[if !IE]&gt; --&gt;

                    <script type="text/javascript">

                    // <![CDATA[

                        function fixA4J() {

                            var bodies = document.getElementsByTagName("body");

                            if (bodies.length > 1) {

                               for (var i = 0; i < bodies.length; i++) {

                                    if (bodies[i].firstChild == null) {

                                        bodies[i].parentNode.removeChild(bodies[i])

                                        break;

                                    }

                                }

                                var heads = document.getElementsByTagName("head");

                                for (var i = 0; i < heads.length; i++) {

                                    if (heads[i].children.length == 1) {

                                        var s = heads[i].firstChild;

                                        heads[i].parentNode.removeChild(heads[i])

                                        document.head.appendChild(s);

                                        break;

                                    }

                                }

                        }

                        window.setTimeout(fixA4J, 100);

                    // ]]>

                    </script>

                    &lt;!-- &lt;![endif]--&gt;

            Basically, it's a timer that checks periodically if RichFaces has broken the page, and then fixes it by removing the extra heads and bodies.

            • 3. Re: firefox 11 and richfaces 3.1.5.GA/jsf 1.1.11 html injection
              Boyd Nolan Newbie

              Has anyone come up with a better solution to this situation? We see the same behavior, but it's very random. Sometimes the extra header and body get injected at the top of the page causing a bunch of blank space. Other times the injection happens below the main body, which allows the page to appear normally. I tried the javascript above and it seems to take care of the header, but the multiple body tags remain...not sure exactly why yet.

              • 4. Re: firefox 11 and richfaces 3.1.5.GA/jsf 1.1.11 html injection
                Renjith Jose Newbie

                Hi Jean,

                 

                We had the same issue in our jsf code. The javascript code worked for us. Thanks a lot!!