Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

<s:property> tag problem

 
Ranch Hand
Posts: 41
  • 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]
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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...
 
Ranch Hand
Posts: 33
  • 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: 41
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic