• Post Reply Bookmark Topic Watch Topic
  • New Topic

Way to reverse a string in JSTL ?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Let's say I have ${alphaOrder} in JSTL and I want to have a variable on my JSP page, ${reverseAlphaOrder} which is all the characters of the string reversed. So for example, if ${alphaOrder} equals "A-D", I would wsant ${reverseAlphaOrder} to be "D-A". The format of ${alphaOrder} will always be "#-#" where "#" is a capital letter.

Thanks, - Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, I would do this in the page controller before the JSP is ever invoked.

Failing that, I'd write an EL function or custom tag to do it.

Failing that, it could probably be done using a combination of EL, JSTL and JSTL-provided EL functions, but it'd be such a mess that I wouldn't really consider doing it this way.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As it turns out, the answer is using the tag library, "http://java.sun.com/jsp/jstl/functions", so the code becomes ...



- Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, like I said; pretty messy and unreadable. But if that doesn't bother you...
 
Paul Clapham
Sheriff
Posts: 21867
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't go so far as to say that code "reverses a string". Sure it reverses strings which happen to be three characters long, of which the middle one is a dash, but that's all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!