walmillard Posted September 22, 2009 Share Posted September 22, 2009 I am wondering if this (bug??) has been addressed:I have a Field CustomerName that contains an & character which is delimted in the XML data to & The CustomerName data displays correctly in the report EXCEPT when it is printed as part of a <style> tag set. IE"<style pdfFontName=\"Helvetica-Bold\">Customer : </style>" + $F{CustomerName}The Customer Data prints ok including the &. But then the <style> tags etc are visible in the report. Its almost like the & breaks the <style></style> tag set?The Field on the report has the "Is Styled Text" box checked. But makes no difference.Removing the <Style> tags all prints OK. Code: I get an Error on "Filling Report" which is:[Fatal Error] :1:73: The entity name must immediately follow the '&' in the entity reference.Perhaps it is in my Jasper lib not in iReport? [edit] Simply checking the " Is Syled Text " box will cause the Fatal Error! Post Edited by walmillard at 09/22/2009 05:29Post Edited by walmillard at 09/22/2009 06:19 Link to comment Share on other sites More sharing options...
mdahlman Posted September 22, 2009 Share Posted September 22, 2009 walmillard, It sounds like a bug, but I haven't heard of this before. You'll need to post this to the JasperReports forum and/or tracker (rather than the iReport forum). Ideally if you can post a small .jrxml that reproduces the problem then it will be easy for others to determine what is going wrong. Regards,Matt Link to comment Share on other sites More sharing options...
svenn Posted September 22, 2009 Share Posted September 22, 2009 & works for stylized text in fact it's a must because using a straight & causes problems. Link to comment Share on other sites More sharing options...
walmillard Posted September 23, 2009 Author Share Posted September 23, 2009 Here are my files. the xml xPath is /dataas u can see the green field breaks the <style></style> tags when the "&" field follows.will post over in the other forum.CheersWalmillardPost Edited by walmillard at 09/23/2009 01:00 Link to comment Share on other sites More sharing options...
svenn Posted September 23, 2009 Share Posted September 23, 2009 Try this"<style pdfFontName='Helvetica-Bold'>" + " Customer Name :" + "</style>" + $F{CustomerName} Link to comment Share on other sites More sharing options...
walmillard Posted September 23, 2009 Author Share Posted September 23, 2009 Thanks for the suggestion, but no dice. Link to comment Share on other sites More sharing options...
mdahlman Posted September 24, 2009 Share Posted September 24, 2009 walmillard, I can reproduce the problem in iReport/JasperReports 3.6. I tweaked your report to do it with a SQL data source, but it shows the same behavior. Please log it as a JasperReports bug. (I'm not sure if it's a bug or an enhancement request... but it should certainly get logged.) Having said that... the workaround is pretty simple. You need to escape your strings to the don't confuse the style tags. Original code that displays badly:"<style forecolor=\"#808080\">Customer Name : </style>" + $F{CustomerName} Modified code that displays nicely:"<style forecolor=\"#808080\">Customer Name : </style>" + org.apache.commons.lang.StringEscapeUtils.escapeHtml($F{CustomerName}) You should include an import statement in the report so you don't need to type "org.apache.commons.lang" everytime. I left it in just for [ugly] clarity. My attached report show it in action. You can run it with any MySQL or PostgreSQL data source (or most other databases) since it just queries hard-coded strings without requiring any particular tables. Regards,Matt Link to comment Share on other sites More sharing options...
walmillard Posted September 25, 2009 Author Share Posted September 25, 2009 Matt, Thanks for your reply. I will post a bug report on the JasperReport tracker.CheersWalmillard Link to comment Share on other sites More sharing options...
gpenn Posted September 25, 2009 Share Posted September 25, 2009 Matt,Would you mind explaining how that works? I have very little experience with iReport, but I'm learning my way around. The code you used was:org.apache.commons.lang.StringEscapeUtils.escapeHtml($F{CustomerName})That looks like it's calling a utility located at commons.apache.org, which will escape problematic characters in $F{CustomerName}. You mentioned including an import satement in the Report so that the utility will be local. How do I do that?Thanks,Gregory Link to comment Share on other sites More sharing options...
mdahlman Posted September 26, 2009 Share Posted September 26, 2009 Gregory, Your basic understanding is exactly correct. I didn't explicitly say it, but you will need to download "commons-lang-2.4-bin.zip" which contains "commons-lang-2.4.jar". That should be easy to Google. commons-lang-2.4.jar will need to be in your classpath. That idea is covered in lots of threads, but the key point is the menu Tools -> Options -> Classpath. To begin with, ignore the import comment. Just get it to work with the fully qualified class name as shown in my sample report. Adding the import later is easy: click on the root report element. From there you will find a property that lets you define imports. Regards,Matt Link to comment Share on other sites More sharing options...
dstreun Posted January 3, 2012 Share Posted January 3, 2012 With German "Umlaut" and French grave/acute accents it is even worse!!! The parser can NOT recognize entities such as "& auml;" or "& eacute;"!Use entity numbers such as "& #228;" instead of entity names such as "& auml;" Link to comment Share on other sites More sharing options...
tkofford Posted February 23, 2012 Share Posted February 23, 2012 I found the information in this thread very useful, but I'm still having a slightly different problem with the & character.I would like to include an HTML link in a text field using an XML file as my data source. The simple case below works and everything renders correctly including the link in my PDF output:Report Text Field Definition <textField isStretchWithOverflow="true"> <reportElement stretchType="RelativeToBandHeight" x="400" y="20" width="155" height="20"/> <textElement markup="html"/> <textFieldExpression><![CDATA[$F{HtmlLink}]]></textFieldExpression> </textField>Desired HTML For help go to: <a href="http://www.google.com">Google</a>XML element <HtmlLink>For help go to: <a href="http://www.google.com">Google</a></ HtmlLink >PDF rendering For help go to: Google However, when I try and add more than one parameter to my link (? for first param, & for multiple params), the & character completely messes up the style and all the source HTML is clearly displayed. For example:Desired HTML For more help go to: <a href="http://support.google.com/bin/static.py?page=portal_groups.cs&hl=en">Google Help</a>XML element <HtmlLink>For more help go to: <a href="http://support.google.com/bin/static.py?page=portal_groups.cs&hl=en">Google Help</a></ HtmlLink >PDF rendering For more help go to: <a href="http://support.google.com/bin/static.py?page=portal_groups.cs&hl=en" type="Reference">Google Help</a> Obviously, I don't want my users to see the source HTML for the "a href" tag, and I don't want to limit my users data by restricting them to only one parameter max for HTML links.Also I do not know where the additional text type="Reference" comes from in the displayed link. It must be some type of short circuit with the & character and the HTML markup processor.Any suggestions?Thanks in advance,TK Post Edited by tkofford at 02/23/2012 15:59Post Edited by tkofford at 02/23/2012 16:00 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now