Sorry, \r was for my special case.

\n should be right for your case!

But definitely go with Mike's suggestion and do a converter...

regards,

Martin

On 12/22/05, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I have now tried to implement your code as component binding but the "\r" 
> isn't replaced and I don't know why.
> The Text is then shown like this: String\nString (Like it's in the Database - 
> no replacement has been done
>
> Here is the code:
> <h:outputText binding="#{components.outputWithBreaks}" 
> value="#{infoMessagesDto.detailmessagetext}" escape="false"/>
>
> I get the text for the Outputtext from Database.
>
> If I don't implement a component binding and just a escape="false" into the 
> outputtext (and the Outputtext has a <br/> (and not a \n or \r) in the text> 
> a carriage return is shown.
>
>
> What could be the problem?
>
> Regards,
> Andy
>
>
> -----Ursprüngliche Nachricht-----
> Von: Martin Marinschek [mailto:[EMAIL PROTECTED]
> Gesendet: Donnerstag, 22. Dezember 2005 17:30
> An: MyFaces Discussion
> Betreff: Re: AW: How to display Line breaks in Outputtext?
>
>
> Yes, of course.
>
> Thanks Mike! You are the better Santa Clause in this case ;).
>
> Even though, with a converter, you'd have to bind it to every
> component you want to treat with this special behaviour. Cause there
> is no such thing as a general string converter! With a renderer, it
> works for all instances of a component type at once...
>
> Of course, my example with a component doesn't make much sense - a
> converter would be cleaner in this case. It would make sense if you'd
> render out stuff differently depending on some other attributes of the
> component or so...
>
> regards,
>
> Martin
>
> On 12/22/05, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
> > Just speculation as I've never tried it, but wouldn't it be easier
> > (and more maintainable) (and more fashionable) to write a converter to
> > do this for you?
> >
> > After all, that's why we have converters separate from renderers....
> >
> > You could also use it for UIInputs as well.
> >
> > -Mike
> >
> > On 12/22/05, Martin Marinschek <[EMAIL PROTECTED]> wrote:
> > > HOHOHO!
> > >
> > > there you go ;)
> > >
> > > even though this is a component, but you can either use that and a
> > > component binding or copy over the code to your renderer.
> > >
> > > regards,
> > >
> > > Martin
> > >
> > > P.S.: Actually, I'm a Christkindl-believer ;)
> > >
> > > public class ComponentBean
> > > {
> > >     /**
> > >      * @return Ausgabetext mit Zeilenumbruch
> > >      */
> > >     public UIOutput getOutputWithBreaks()
> > >     {
> > >          return new OutputText();
> > >     }
> > >
> > >     /**
> > >      * OutputText wobei <br/> beim Rendern als Zeilenumbruch
> > > interpretiert wird.
> > >      */
> > >     public static final class OutputText extends HtmlOutputText
> > >     {
> > >         public OutputText()
> > >         {
> > >             super();
> > >         }
> > >
> > >         public void encodeEnd(FacesContext context) throws IOException
> > >         {
> > >             String text = RendererUtils.getStringValue(context, this);
> > >             text = HTMLEncoder.encode(text, true, true);
> > >             text = text.replaceAll("\r","<br/>");
> > >             renderOutputText(context, this, text, false);
> > >         }
> > >
> > >         public static void renderOutputText(FacesContext facesContext,
> > >                                             UIComponent component,
> > >                                             String text,
> > >                                             boolean escape)
> > >             throws IOException
> > >         {
> > >             if (text != null)
> > >             {
> > >                 ResponseWriter writer = facesContext.getResponseWriter();
> > >                 boolean span = false;
> > >
> > >                 if(component.getId()!=null &&
> > > !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
> > >                 {
> > >                     span = true;
> > >
> > >                     writer.startElement(HTML.SPAN_ELEM, component);
> > >
> > >                     HtmlRendererUtils.writeIdIfNecessary(writer,
> > > component, facesContext);
> > >
> > >                     HtmlRendererUtils.renderHTMLAttributes(writer,
> > > component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
> > >
> > >                 }
> > >                 else
> > >                 {
> > >                     span =
> > > HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,component,
> > >                             
> > > HTML.SPAN_ELEM,HTML.COMMON_PASSTROUGH_ATTRIBUTES);
> > >                 }
> > >
> > >                 if (escape)
> > >                 {
> > >                     writer.writeText(text, JSFAttr.VALUE_ATTR);
> > >                 }
> > >                 else
> > >                 {
> > >                     writer.write(text);
> > >                 }
> > >
> > >                 if(span)
> > >                 {
> > >                     writer.endElement(HTML.SPAN_ELEM);
> > >                 }
> > >             }
> > >         }
> > >
> > >     }
> > > }
> > > On 12/22/05, [EMAIL PROTECTED]
> > > <[EMAIL PROTECTED]> wrote:
> > > > Oh Yes Santa (Martin) Claus ;)
> > > > Would be great if you could send me the code. I would be terribly 
> > > > grateful if you could to that!
> > > > BIG Thx!
> > > >
> > > > Regards,
> > > > Andy
> > > >
> > > >
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Martin Marinschek [mailto:[EMAIL PROTECTED]
> > > > Gesendet: Donnerstag, 22. Dezember 2005 16:47
> > > > An: MyFaces Discussion
> > > > Betreff: Re: AW: How to display Line breaks in Outputtext?
> > > >
> > > >
> > > > Yes, basically you'll need to do this.
> > > >
> > > > You want the code for such a thing from me?
> > > >
> > > > You'll have to nicely ask for a christmas present if you really want it 
> > > > ;)
> > > >
> > > > regards,
> > > >
> > > > Martin
> > > >
> > > > On 12/22/05, [EMAIL PROTECTED]
> > > > <[EMAIL PROTECTED]> wrote:
> > > > > So I have to write my own renderer for the Outputtext?
> > > > >
> > > > > Regards,
> > > > > Andy
> > > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Martin Marinschek [mailto:[EMAIL PROTECTED]
> > > > > Gesendet: Donnerstag, 22. Dezember 2005 16:30
> > > > > An: MyFaces Discussion
> > > > > Betreff: Re: AW: How to display Line breaks in Outputtext?
> > > > >
> > > > >
> > > > > What you usually do is to replace the renderer of the output-text
> > > > > component - and replace all occurrences of \n with <br/> there.
> > > > >
> > > > > Plus: you need to make sure that escape="false".
> > > > >
> > > > > regards,
> > > > >
> > > > > Martin
> > > > >
> > > > > On 12/22/05, [EMAIL PROTECTED]
> > > > > <[EMAIL PROTECTED]> wrote:
> > > > > > How can I replace the \n with a <br/> on the output? By javascript?
> > > > > > Because when I write <h:outputText value="Hello<br/>World"/> It 
> > > > > > doesn't work.
> > > > > >
> > > > > > If I use the pre Tag, what can happen with the layout?
> > > > > >
> > > > > > Regards
> > > > > > Andy
> > > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Luiz Carlos Geron [mailto:[EMAIL PROTECTED]
> > > > > > Gesendet: Mittwoch, 21. Dezember 2005 14:13
> > > > > > An: MyFaces Discussion
> > > > > > Betreff: Re: AW: How to display Line breaks in Outputtext?
> > > > > >
> > > > > >
> > > > > > > So the user has to write \n hardcoded into the textarea? Isn't 
> > > > > > > there a way
> > > > > > > to recognize a Carriage Return, when the user presses the CR Key?
> > > > > > No. When you submit a form that contains a textarea, if you have 
> > > > > > typed:
> > > > > >
> > > > > > line
> > > > > > other line
> > > > > >
> > > > > > Then if you make:
> > > > > >
> > > > > > String str1 = this.getInputTextarea1
> > > > > > ().getValue().toString().replace("\n","<br>");
> > > > > >
> > > > > > You'll get "line<br>other line". Don't do this replace, since maybe 
> > > > > > you want
> > > > > > to put the value in a textarea again.
> > > > > >
> > > > > > > And I don't unterstand what you mean with the <pre> tag.
> > > > > > > Do you mean just: <pre><h:outputText value="Hello/nWorld"/></pre> 
> > > > > > > and the
> > > > > > > Text is shown as Hello
> > > > > > > World
> > > > > > >
> > > > > > > ??
> > > > > > Yes, you can also replace (on the output) the "\n" with <br>. I 
> > > > > > recommend this
> > > > > > last option, since it don't use the <pre> html tag, wich can break 
> > > > > > you
> > > > > > layout.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > http://www.irian.at
> > > > >
> > > > > Your JSF powerhouse -
> > > > > JSF Consulting, Development and
> > > > > Courses in English and German
> > > > >
> > > > > Professional Support for Apache MyFaces
> > > > >
> > > > >
> > > > > ______________________________________________________________________
> > > > >
> > > > > This email and any files transmitted with it are confidential and
> > > > > intended solely for the use of the individual or entity to whom they
> > > > > are addressed. If you have received this email in error please notify
> > > > > your system manager.
> > > > >
> > > > > This footnote also confirms that this email message has been swept
> > > > > for the presence of computer viruses.
> > > > > ______________________________________________________________________
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > http://www.irian.at
> > > >
> > > > Your JSF powerhouse -
> > > > JSF Consulting, Development and
> > > > Courses in English and German
> > > >
> > > > Professional Support for Apache MyFaces
> > > >
> > > >
> > > > ______________________________________________________________________
> > > >
> > > > This email and any files transmitted with it are confidential and
> > > > intended solely for the use of the individual or entity to whom they
> > > > are addressed. If you have received this email in error please notify
> > > > your system manager.
> > > >
> > > > This footnote also confirms that this email message has been swept
> > > > for the presence of computer viruses.
> > > > ______________________________________________________________________
> > > >
> > >
> > >
> > > --
> > >
> > > http://www.irian.at
> > >
> > > Your JSF powerhouse -
> > > JSF Consulting, Development and
> > > Courses in English and German
> > >
> > > Professional Support for Apache MyFaces
> > >
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
> ______________________________________________________________________
>
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> your system manager.
>
> This footnote also confirms that this email message has been swept
> for the presence of computer viruses.
> ______________________________________________________________________
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Reply via email to