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

    Ajax response not preserving line breaks

    Adam Michalik Newbie

      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
          Andrey Markhel Newbie

          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
            Adam Michalik Newbie

            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
              Adam Michalik Newbie

              Here's an example:




              <?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">
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
              <h:form id="testForm">
                  <h:outputText value="#{testBean.text}" style="white-space: pre;"/>
                <a4j:commandButton value="RELOAD" action="#{testBean.reload}" reRender="testForm"/>




              package test;


              import org.ajax4jsf.model.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






              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
                Adam Michalik Newbie

                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?