• Post Reply Bookmark Topic Watch Topic
  • New Topic

Special Characters '&' and ':'  RSS feed

 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Whenever there are characters such as '&' or ':' that are stored in the attributes of beans which are string arrays, they won't display in a JSF (1.2 Mojarra) page.
In fact, the entire h:dataTable will not get rendered. I'm not seeing any exceptions thrown in my Tomcat 6.0.20 logs either.

I know that when the data are stored in my beans that the special characters are in there, via println() statements.

In this "beanName" example, the ADDRESS field sometimes contains addresses that are the intersections of two roads, such as: 1st & Washington. When this particular search ocurrs, no results are rendered for this dataTable and I'm of the opinion it has something to do with the '&' character. When I change the underlying data and replace '&' with the word "and", the record is displayed.

Strangely, I can output the '&' and ':' characters to the page as strings, but not via the beanName.attribute in a method binding statement.

Why is that?




private BACasemap[] bacasemaprecord;

 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 5 "magic" characters in XML, and they apply here. Those characters are "& ' " < >". You can't use these magic characters directly because they're ambiguous in terms of the XML meta-language, so you'll usually need to use entity objects in their place. The equivalent entity definitions are "&amp; &apos; &quot; &lt; &gt;". Note the terminating semicolons - they're critical.
 
dwarakanathan thiru
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This means we cannot use any editable fields for displaying them properly?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dwarakanathan thiru wrote:This means we cannot use any editable fields for displaying them properly?


I think that they're discussing that over in this thread: http://www.coderanch.com/t/488943/JSF/java/Usage-inputTextarea-JSF . But if you mean "can you enter a text such as 'Savings & Loan' in an ordinary textinput control?", that's not a problem and you don't need to so anything special.
 
Bart Kummel
author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Most JSF components have an escape attribute. If you set that to false, the "magic" characters will be displayed as expected.

Best regards,
Bart
 
dwarakanathan thiru
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,
I have a text field and drop down. On change of the drop down, I wanted to populate the text area. I can very well past MANDARIN in a text area, but its the way it is populated is tricky.

If at all the "&" was not getting converted to "& A M P ;" in my JSP file, the chinese character would have displayed properly on populate.

Bart,
I agree. But for inputTextArea this attribute is not present.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!