I retrieved value (Note 3 spaces after 1) for field "xxx" from db
I trimmed it and put it in my bean class.
When i displayed this value in jsp using <s:property value="xxx"> tag
I expected my application to display (Note 3 spaces after 1)
But it displayed (Note 1 space after 1)
Reason: When text is converted to html, HTML treats multiple spaces as one space.
Is my understanding correct?
I had to get all spaces between texts
Solution: To achieve this i added <pre> tag before and after <s:property value="xxx"> tag
This solved my problem.
But one small problem still exists.
After adding pre the font style of display has changed in this <td> when compared to other <td>
Can somebody explain me why this is happening and how to resolve this??
Archana in your action where this property is being set, you can use s regular expression to convert spaces to . That way if there are 3 spaces, they are rendered as 3 spaces in the browser and you don't have to use pre tag...
The possible solutions
1) you replace spaces with "& nbsp;" (without that space, I can't spell it right because the forum doesn't use <pre> tag ) before passing it to jsp
2) you use styling for pre
3) put your property tag into the element with styling 'white-spaces: pre' (see http://www.w3schools.com/CSS/pr_text_white-space.asp)
note that solutions 1) and 2) are actually some hacking.
nbsp is intended to be non-breaking spaces, not non-sticking. Thus if some browser ignores you putting three spaces in a row displaying one instead, then he is not guilty for that.
And "pre" means preformatted, not preserved-white-space text. Its use is generally for code samples and so on.
posted 11 years ago
I took you suggestion 2
I did styling for pre.
It worked partially
I am getting font style for value xxx same as other ones in screen.
<pre STYLE="font-family:'arial';"><s:property value="xxx" /></pre>
But one problem is its aligning itself to top of the cell although it has only one line.
I tried to add valign="middle" in pre tag's style attribute and also in td tag.
But didnt work.
Any suggestion to fix this small issue?
Any help appreciated as it might come out as bug within next few days.