webtier@glassfish.java.net

Re: [webtier] JSF 2.0: Spaces not Preserved before h:outputText values

From: Jim Driscoll <Jim.Driscoll_at_Sun.COM>
Date: Wed, 19 Aug 2009 19:41:39 -0700

This is a known issue, and has been discussed recently on this forum.

The workaround is to put a non-breaking space in between:

<h:outputText value="#{b.foo}"/> &#0160;<h:outputText value="#{b.foo}"/>

Yeah, I know, lame. The reason why is complicated, and only comes into
play when there is pure space between two components.

Incidentally, this also works:

#{b.foo} #{b.foo}

because outputText isn't required in the simple case anymore.

Jim

On 8/19/09 10:09 AM, webtier_at_javadesktop.org wrote:
> Note: I am running Glassfish 3 with Mojarra 2.0.0 (Beta1 b13) on Windows Vista with JDK 1.6.0_15. Identical results on Firefox, IE, Safari, and Chrome.
>
> ===================================
> Quick Summary: whitespace is not preserved before h:outputText. The following outputs "blahblah", not "blah blah".
> <h:outputText value="#{b.foo}"/> <h:outputText value="#{b.foo}"/>
>
> ===================================
> Details: whitespace from the original .xhtml file is not preserved before h:outputText. This is true regardless of the type (String, int, double) of the property. You can download a sample Eclipse project that includes the code below and demonstrates the issue from http://www.coreservlets.com/jsf2/
>
> For example, here is a snippet of test.xhtml:
>
> Foo<h:outputText value="#{myBean.field1}"/> <h:outputText value="#{myBean.field2}"/> <h:outputText value="#{myBean.field3}"/>
> <hr/>
> Foo
> <h:outputText value="#{myBean.field1}"/>
> <h:outputText value="#{myBean.field2}"/>
> <h:outputText value="#{myBean.field3}"/>
> <hr/>
> Foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> <h:outputText value="#{myBean.field1}"/>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> <h:outputText value="#{myBean.field2}"/>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> <h:outputText value="#{myBean.field3}"/>
>
> Here is the corresponding bean:
> package myPackage;
> import javax.faces.bean.*;
>
> @ManagedBean(name = "myBean")
> @RequestScoped
> public class MyBean {
> public String getField1() {
> return ("field1");
> }
> public int getField2() {
> return (123);
> }
> public double getField3() {
> return (45.67);
> }
> }
>
> In all three cases, the output is "Foofield112345.67", with no spaces.
>
> Cheers-
> - Marty (hall_at_coreservlets.com)
> [Message sent by forum member 'martyhall' (martyhall)]
>
> http://forums.java.net/jive/thread.jspa?messageID=361210
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>