Meaningless Drivel is fun!
The moose likes Struts and the fly likes <s:property> tag problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<s:property> tag problem" Watch "<s:property> tag problem" New topic

<s:property> tag problem

Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
I am using Struts2 in my application

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??


(I hope i have stated my doubt clearly.)

[Edit AG: corrected HTML in page]
Ankit Garg

Joined: Aug 03, 2008
Posts: 9404

Archana in your action where this property is being set, you can use s regular expression to convert spaces to &nbsp;. 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...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Pavel Kazlou
Ranch Hand

Joined: Sep 07, 2009
Posts: 33
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

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.
Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
Hi Pavel,
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.
David Newton

Joined: Sep 29, 2008
Posts: 12617

How about asking in the HTML/JavaScript forum, since this has nothing to do with Struts?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: <s:property> tag problem
It's not a secret anymore!