2 Replies Latest reply on Nov 13, 2008 9:57 AM by kapitanpetko

    Stupid <br> question

    kirkor.grzegorz.bernas.com.pl

      Hi, sorry for stupid question but I can't find any information about:
      I have <h:inputTextarea /> and I want to disable HTML tags but when I display content of this I want to convert new line characters to <br />


      How to do it?

        • 1. Re: Stupid <br> question
          mail.micke

          Hi


          You could create a Facelets function or a Seam component to do this (since the enhanced EL allows for parameter passing).



          @Name("myHelper")
          @Scope(APPLICATION)
          public class MyHelper ...{
          
          
            public String nlToBr(final String str){
               String retVal = null;
               retVal = //replacing the new lines
               return retVal;
            }
          }
          



          Then in the xhtml you can do this:


          <h:outputText value="#{myHelper.nlToBr(myBacking.theText)}"/>
          



          Or create a facelets function and have this:


          <h:outputText value="#{foo:nlToBr(myBacking.theText)}"/>
          



          - Micke

          • 2. Re: Stupid <br> question
            kapitanpetko

            If all you want to do is preserve line breaks when displaying user-entered text,
            you could just set white-space: pre in CSS for your text areas. Like so:


            <h:inputTextarea rows="3" cols="40" readonly="true" 
               value="#{mybean.remark}"  style="white-space: pre" />