1
<c:set var="xmlDocumentId" value="${id}" scope="request" />
<s:set var="xmlDocumentId" value="%{id}" scope="request" />

are formatting id based on locale, setting xmlDocumentId to "12,345" while:

<c:out value="${id}" />
<s:property value="%{id}" />

are outputting "12345".

Any ideas how to break this behavior?

Roman C
  • 49,761
  • 33
  • 66
  • 176
tzimnoch
  • 216
  • 1
  • 13
  • Remove scope="request". – Aleksandr M Jun 19 '14 at 07:54
  • Removing scope makes the variable unavailable to where it is being used. – tzimnoch Jun 19 '14 at 15:36
  • Where do you want to use it? – Aleksandr M Jun 19 '14 at 15:38
  • In the request. It is being used by a property to generate a link to the document. e.g. xmlDocumentUrl=xmlDocument.action?xmlDocumentId={xmlDocumentId} I can work around this by creating another accessor that returns the id as a string rather than a long, but I'd rather learn why c:set and s:set are formatting numbers. – tzimnoch Jun 19 '14 at 15:49
  • How do you construct url-s? Use S2 tag to do that. Then there is no need to put it in the request. – Aleksandr M Jun 19 '14 at 19:33
  • I have a business requirement that URLs be defined in a properties file and not embedded in the JSP. I have no control over that. There are lots of workarounds that remove my need to understand this issue, nevertheless, I would like to learn the answer to the question of how to use set tags (or some other jsp tag) to bypass formatting and do a straight-up number-to-String conversion. – tzimnoch Jun 19 '14 at 19:50

3 Answers3

1

Because you are getting value with getText or <s:text> tag your long value gets formatted according to locale. To prevent this from happening convert your long to string.

With <s:set> tag you can call toString() method directly in value attribute.

<s:set var="xmlDocumentId" value="id.toString()" scope="request" />

For the concrete formatting algorithm take a look at java.text.MessageFormat class and its subformat method.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
0

Once you know how to format numbers in Java, in Struts2 <s:property/> tag you can use getText() to format your number in the desired way, for example :

<s:property value="getText('{0,number,#,##0}',{id})"/>
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Andrea: Thank you, but the issue is that the set tag is formatting my numbers when I do not want it to. How do I stop the set tag from formatting numbers? – tzimnoch Jun 19 '14 at 15:35
-2

Try this

<s:text name="id" > <s:param name="value" value="id"/> </s:text>
Roman C
  • 49,761
  • 33
  • 66
  • 176
xrcwrn
  • 5,339
  • 17
  • 68
  • 129