• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to format a string inside within a "<c:out value='${" line

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following:



The number is displayed as:
12345678901234567890

I want to group the numbers in pairs of 4 as per below:
1234 5678 9012 3456 7890
 
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order of likelihood, I'd write: a custom EL function to perform the formatting, or a custom tag to perform the formatting, or pre-format the string in the controller.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering, if this is expected to be a number, why the escapeXml Attribute is specified as false?

I would think yo uwould only want to set escapeXml to false in the specific cases where you are expecting to write HTML onto the page.

Otherwise you have a potential security hole.


 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point, Stefan. If the source of the string is untrusted, the output should always be escaped. Otherwise, there's really no point to even using <c:out> at all; just use the EL expression.
 
Jason Smit
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you guys not put something together for me to test and try to implement?
 
Bear Bibeault
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not how things work here. Try putting something together, post the code and whatever issues you are having with it.

Path of least resistance is pre-formatting the string in the controller. (But as I said, I'd personally go for the EL function.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!