Pages

Monday, June 06, 2011

Internet Explorer 8 and XHTML Comments

Never Internet ExplorerImage via Wikipedia
Yesterday, I posted a JSF 1.2 login example using nearly pure JSF. I discovered the answer to a bug which was not documented anywhere that I can find. The issue has to do with comments. Internet Explorer 8 seems to choke on them. When I created the example yesterday, I tested it extensively on a number of modern browsers that I have available to me. It works perfectly as expected... with one exception. The other browsers treat the <-- COMMENT --> perfectly. Internet Explorer can not seem to digest it. There is likely some reason (READ EXCUSE) for this behavior, but I can not seem to fathom it. The result on the login page is to cause the browser to spin until timeout, and then re-render the previous page.

This error seems to not care if the DOCTYPE is declared before, or after the comment. I checked just in case.

OK...So I found a bug, but how do you fix it. Well, it is really easy.
  1. Remove all the comments from the page. This is bad for obvious reasons.
  2. If you are using facelets, we have two methods available depending on the version of JSF you are using.
    • JSF 1.2 - Add this context parameter to the web.xml
      <context-param>
              <description>
                  If comments are enabled, the copyright header will prevent the login form
                  from working on Internet Explorer. Alternatively, you can remove the copyright
                  header.
              </description>
              <param-name>facelets.SKIP_COMMENTS</param-name>
              <param-value>true</param-value>
          </context-param>
      
    • JSF 2.x - Add this context parameter to the web.xml
      <context-param>
              <description>
                  If comments are enabled, the copyright header will prevent the login form
                  from working on Internet Explorer. Alternatively, you can remove the copyright
                  header.
              </description>
              <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
              <param-value>true</param-value>
          </context-param>
      

Once you disable the comments, the login page works perfectly. The comments also apparently cause issues with rendering RichFaces pages which now work without issue, or compatibility mode hacks.
Enhanced by Zemanta

No comments:

Post a Comment