myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pedro_burglin <>
Subject h:inputText collapses multiple space characters
Date Thu, 28 Jul 2011 17:57:16 GMT

I am not sure if this was already answered but I couldn't find any working
solution for this issue yet.

The problem I am having is that h:inputText collapses multiple space
characters into a single space character.

Background: web app using MyFaces 1.2.9 (I tested it with MyFaces 2.0.7 with
same results)

Steps to reproduce the issue:
1. User fills h:inputText form field with multiple spaces. For example, "ABC   
ABC" with 4 spaces in the middle.
2. I confirmed that the value is saved correctly in the database with all 4
spaces -> "ABC    ABC".
3. However, when form screen is refreshed the h:inputText shows value with
just a single space in the middle -> "ABC ABC"

AFAI can see this is not something caused by HTML, CSS or the browser
because when I view the page source from the client side I see "ABC ABC"
(i.e. 1 space), so this must be something happening server-side (MyFaces?

Question is, how can I prevent this behavior of multiple spaces being
replaced with 1 space?

I found that all calls to my bean's getter method during the save and screen
refresh process returned the correct value with multiple spaces. But still
the inputText value has only 1 single space.

I got the same results with brand new AppFuse 2.0.2 and 2.1 JSF projects
(MyFaces 1.2.2 and 2.0.4 respectively). Saved a password hint like "A male   
kitty." (4 spaces between "male" and "kitty") but the edit profile screen
also presents it as "A male kitty." (1 space between "male" and "kitty").

Odd I could not find this specific problem discussed in many places and none
had a potential solution. Some responses (e.g.
mentioned to use <pre> and CSS to avoid that but the code updates below did
not made any changes to that behavior.

    <t:htmlTag value="pre">
    <h:inputText value="#{userForm.user.passwordHint}" id="passwordHint"
required="true" style="white-space: pre;">
        <v:commonsValidator client="true" type="required"

I could use something like these PRE tags (if it worked) but I thought by
default JSF shouldn't transparently remove content from the value of a bean
like it is doing in this example. In this thread
( Luigi
mentioned that JSF should preserve spaces in h:inputText but this is not
what is happening.

Hopefully someone already faced this issue and can share how it can be fixed
but any help (e.g. suggestions of things I could try) is appreciated,
View this message in context:
Sent from the MyFaces - Users mailing list archive at

View raw message