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