Jump to content
Changes to the Jaspersoft community edition download ×

Is Styled text and &


walmillard

Recommended Posts

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:29



Post Edited by walmillard at 09/22/2009 06:19
Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

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

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

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

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

  • 2 years later...
  • 1 month later...

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:59



Post Edited by tkofford at 02/23/2012 16:00
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...