Jump to content
Changes to the Jaspersoft community edition download ×

how to find and replace text

shesh anand

Recommended Posts

Look i have generated a report using iReport which fetches me the data from my database and prints it into a pdf ....but now what happens here is that the data the query string is almost same every time...what if i want to let the user decide to choose as to what data he needs to take print of...by this i mean let him choose the data what he wamts to print....that would obviously bring a change in querystring inside report.jrxml...but the problem is how to do that dynamically.....


do i need to read that report.jrxml and find the place where i need to replace that selected parameters which i get from request.getParameter() to the required places in that report.jrxml's querystring tag also with a where condition....and then again write it into the same report.jrxml with the updated replaced text and compile it and generate a report.jasper for it...


If yes please let me know the code to do this... i mean how to read it..i mean the report.jrxml then find the querystring tag and then make the replacements and then again write the updated report in report.jrxml...


also if there is some other solution please let me know that too....



here is that snippet of code which i need to read...do the modifications and write it again to report.jrxml








Also i need to make changes to the field expressions accordingly..

below is the snippet of that too..


<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>


<textFieldExpression class="java.lang.String"><![CDATA[$F{surname}]]></textFieldExpression>


<textFieldExpression class="java.lang.String"><![CDATA[$F{address}]]></textFieldExpression>


<textFieldExpression class="java.lang.String"><![CDATA[$F{phoneno}]]></textFieldExpression>



what i want really is pass the query like select name,surname from myemployees..then it should print the record for those two fields only...if i pass select * from myemployees then it should print all the values...and when i pass select * from myemployees where name='Mr.X'...then for all the values should be shown there for Mr.X ...that means i want good of both worlds.....what's happening is that while i have put the query as following....then again i changed as follows..


The snippets of code are as follows




String name=resultSet.getString(1);


System.out.println (hashMap.get("name"));

System.out.println (hashMap);






JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, hashMap,connection);



JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, hashMap,connection);




...then what i get is a blank report and when i print it on the console then, which i did intially just to confirm whether map has those objects or not...then the values in the map are printed on the console but the report that i get is a big B L A N K...i am using <textFieldExpression ><![CDATA[$P!{name}]]></textFieldExpression>



what else do i need to do...is there any <printExpression></printExpression>...please let me know how to use it



Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic



There is no simple answer to your questions, but I can give you several pieces of the puzzle and then you decide what you need to do.


You can create report templates using the JasperReports API, like shown in the /demo/samples/noxmlreport sample provided with the project source files.

Using the API you can modify existing report templates that you load from JRXML files using the JRXmlLoader.


If it only about the query, then maybe the report does not have to change and the query itself can be dynamic if you use $P!{} parameters like shown in the /demo/samples/query sample. Note that the whole query can be supplied as a single $P!{} parameter in <queryString>.


Inside a report template you can locate various elements in a band by looking for their "key" attribute.


I hope this helps.


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...