File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<s:property> tag problem

 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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??

Thanks,
Archana

(I hope i have stated my doubt clearly.)

[Edit AG: corrected HTML in page]
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Pavel Kazlou
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about asking in the HTML/JavaScript forum, since this has nothing to do with Struts?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic