Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

escaping strings using Struts html:text tag

 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I recently posted a question regarding how to escape quote characters generated by el expressions
(see the following link: http://www.coderanch.com/t/288914/JSP/java/el-expressions-escaping-Javascript-strings)

Bear Bibeault answered superbly may I add

Now I'm stuck with a similar problem with a Struts custom tag, specifically the html:text tag. It's trying to display a String containing a single quote (') and is escaping the quote with the sequence


The previous solution was to write an el function that parsed the String and prededed any occurances of ' with a \.

Does anyone know how I can do something similar with a Struts custom tag?
 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that didn't display as I had hoped... View the page source if you want to see the escape characters.
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the html:text tag you are using?
How are you setting its value?
 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the time delay, I guess I'm across the pond from you guys. I've been looking deeper into the problem, and it doesn't seem to be anything to do with the Struts tag, rather it seems to be a browser issue. I'm totally stumped...

I ripped out the Struts html:text tag and replaced it with a regular, old-fashioned text input field. I hard-coded a last name in the "value" attribute as follows:



For some reason, it's still appearing as O& #39;Reilly (I've put a space in so the escape characters are displayed this time)

I have tried to replicate this on my desktop with a static html page but it won't work.
 
Colin Shine
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved it!

A bean:write tag was being used further down the page to generate some javascript to update the value of the text box. Evidently, bean:write encodes characters such a quotes, which is fine in the body of a html page, but is displayed exactly 'as is' in the text field.



This javascript overrides the initial value, even my hard-coded one :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic