4 Replies Latest reply on Sep 28, 2010 5:31 AM by hattifnat

    Ajax response not preserving line breaks

    hattifnat

      Hi! I have a rich:dataTable containing in one column some text with CSS white-space: pre; setting. The text is formatted using line breaks. When the page renders for the firs time, it looks fine (ie. the text is formatted properly). But when I use some filtering on the table and rerender the table's content with AJAX (a4j:support), the AJAX response does not contain the line breaks, so the formatting is broken and everything is displayed in a single line.

      Is it a "normal" AJAX behavior or some kind of a RF bug? Is there a way to preserve the line breaks in the response?

        • 1. Re: Ajax response not preserving line breaks
          amarkhel

          Could you paste your code? Btw, is this problem related to particular browsers or all? Do you try set default parser to NEKO or NONE?

          1 of 1 people found this helpful
          • 2. Re: Ajax response not preserving line breaks
            hattifnat

            I'll try to produce a simple example from my real code asap. I checked the problem exists on Firefox 3.6 and Chrome 6.0, I'll confirm Safari, Opera and IE tomorrow. Why I think the problem is on the server side is that using Firebug I can see the incoming response XML and it doesn't contain any line breaks.

             

            I didn't realize it is possible to configure different parsers. I'll try that and post the results.

             

            Thanks for the hints!

            • 3. Re: Ajax response not preserving line breaks
              hattifnat

              Here's an example:

               

              test.xhtml

               

              <?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">
              <html
                  xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:f="http://java.sun.com/jsf/core"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:c="http://java.sun.com/jstl/core"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:a4j="http://richfaces.org/a4j">
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                  <title></title>
              </head>
              <body>
              <h:form id="testForm">
                <div>
                  <h:outputText value="#{testBean.text}" style="white-space: pre;"/>
                </div>
                <a4j:commandButton value="RELOAD" action="#{testBean.reload}" reRender="testForm"/>
              </h:form>
              </body>
              </html>

               

              TestBean.java

               

              package test;

               

              import org.ajax4jsf.model.KeepAlive;

               

              @KeepAlive
              public class TestBean {

               

                  private static final String TEXT = "Line one\r\nLine two\r\nLine three\r\nLine four";

                  // Using \n only makes no difference

               

                  public String getText() {
                      return TEXT;
                  }

               

                  public void reload() {
                      // empty
                  }
              }

               

              faces-config.xml

              <managed-bean>
                  <managed-bean-name>testBean</managed-bean-name>
                  <managed-bean-class>test.TestBean</managed-bean-class>
                  <managed-bean-scope>request</managed-bean-scope>
              </managed-bean>

               

              Result

              On initial page load, the output is:

               

              Line one

              Line two

              Line three

              Line four

               

              After reRender, it's:

               

              Line one Line two Line three Line four

               

              The initial HTTP response contains line breaks. The later AJAX response contains no line breaks.

               

              Confirmed on FF 3.6, IE 8, IE 8 as IE 7, Opera 10.61, Chrome 6.0, Safari 5.0.

               

              I'll try different parsers now.

              • 4. Re: Ajax response not preserving line breaks
                hattifnat

                OK, I switched to NEKO (had to add two dependencies: nekohtml and xercesImpl - marked as optional in richfaces-impl pom.xml) and it works fine. I'm still not sure whether the default TIDY parser should expunge the line breaks - can anyone confirm?