Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent HTML Removing Successive spaces

I have an issue in a JSP page where I have to display a generated message onscreen based on a string. It all works fine until one of the account numbers contains two spaces.

So, I have this HTML:

    <logic:notEqual name="migrationsMessage" value="">
        <div style="color:Red;font-weight:bold">
            <bean:write name="solasDetailsForm" property="migrationsMessage"/>
        </div>
    </logic:notEqual>

When the field migrationsMessage contains this:

<input type="hidden" name="migrationsMessage" value="A  123456W has migrated to A 123456.">

The output on the screen is this:

“A 123456W has migrated to A 123456.”

The second space after the first A is removed. I tried to alter the style to be this but it didn't help:

    <logic:notEqual name="migrationsMessage" value="">
        <div style="color:Red;font-weight:bold;white-space:pre">
            <bean:write name="solasDetailsForm" property="migrationsMessage"/>
        </div>
    </logic:notEqual>

Any ideas what is going wrong?

like image 808
mcquaim Avatar asked Feb 07 '23 20:02

mcquaim


2 Answers

white-space: break-spaces solved for me. More on white-spaces here. They have this awesome table: enter image description here

like image 124
delki8 Avatar answered Feb 09 '23 08:02

delki8


function encodeWhiteSpaces(str) {
   return str.split('').map(function(c) { return c === ' ' ? '&nbsp;' : c }).join('');
}

The string is converted to an array(split), then created a new arrray (map) with all white spaces converted to &nbsp;, finally join the array back to a string (join).

like image 32
Charlie Avatar answered Feb 09 '23 09:02

Charlie