Jump to content
Changes to the Jaspersoft community edition download ×

Dynamic inputs for jrxml


Recommended Posts



I am trying to generate reports using iReport1.2.7 where in i create a template using <querystring>




<querystring> select * from emp</querystring>


This would give me a template design which i am uploading in to my repository database and then calling the design while generating the report.


All the UI is done via jsp.

Uploading a template file created using iReport and then storing the template in db. Also storing the generated report too in db.


All this process can be done via web. Now if the user wants to edit the template inputs , the mechanism which i am following as if now is to let him create his own design with appropriate inputs @ the query level and then upload that tempalate in to the product.


But thats not the way i guess it shoule be done althoug i have been following this approach as an alternhative for the time being.


Can anyone tell me or guide me how to create a report with dynamic inputs with out changing the template.


Like selecing the country name as India in the ui should give me report for all employees in India


where in the querystring sould take the params as


<querystring>select * from emp where country like %india%</querystring>


the original query was

<querystring> select * from emp</querystring>


I hope i was able to mention clearly what i need.


any suggestions/ideas most welcome.


Looking ahead for a positive reply.


Thanks and regards,

Sesha Sai.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

This can be done by passing parameters to query string.


First,u need to create/define parameter expression

The below code will accept a string value from user:

<parameter name="myInput" isForPrompting="true" class="java.lang.String"/>


Then, u need to pass the input/parameter value to query string

[code]<queryString><![CDATA[select * from emp where country=$P{myInput}]]></queryString>


I hope i answer your question.

Post edited by: anandharaj, at: 2007/01/07 12:05

Link to comment
Share on other sites

Hi Anand,


First of all..Sorry for delayed response was on a holiday trip so could check ur reply and thank u so much for u reply.


I have tried with the instructions that u have given me and it worked out fine in iReport.


What i have done is


Created a new query based report template and added a parameter with isForPrompting="true" . So when i run the report i am getting a dialog box asking me to input the value of employe name and when i do that i am getting the desired result and report.


Works gr8 so far.


My next doubt would be How can i punch in the input values from a jsp page to the template design with out having the dialog box.


I mean i will show all tthe employee names in a drop down list and when i select the name of any one employee and then click on submit i should be getting the report of that particular employee.. similar to wat we are doing in iReoirt where in i am typing the name of the employee in the dialog box.


I hope i was clear.. :-)


Looking ahead for ur reply.




Link to comment
Share on other sites

Hi Seshasaib


Yes, this can be done using input control.The jrxml code is same except you need to set isForPrompting="false"


JSP pages.... are you talking about JI (JasperIntelligent)?

If yes, basically when u create a Report Unit there is an option to set the Input control.So, here you have to create an input control but make sure the name is same as the parameter name.

When you create the input control, there are some options like Single value, Single select list of values and etc...

If you decide to create an input where users have to enter data/value theirself...then you create the input as Single value othervise if you just want user select, for example the empleye name from list then you have to create Single/Multi Select List.



Guys, if you think that my explanation is not the right way orthere is another way, please advise and correct this.

This is usefull for all of us.

Link to comment
Share on other sites

Hi Anand,


I am not using the JI for UI. I'm doing it via a normal jsp page along with struts /portal.


SO if i say that, I choose the employee name from a drop down list and get that value from the jsp via request.getParamter("selectedEmployee") and pass this info to the action class(GenerateReport.java)


I have made the isForPrompting='false' so its not giving me any dialog box to enter the input as if now..thats understandable. My next doubt would be how wud i pass the input paramter to that parameter field of jrxml.


I am doing the following process as if now to generate a report.


System.out.println("Trying to get connection"«»);
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@ipaddress:1521:orcl","sesha_uid","sesha"«»);
System.out.println("Connection established"«»);
Map parameters = new HashMap();
JasperDesign jasperDesign = JRXmlLoader.load("C:\IR130\org.jrxml"«»);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint print = JasperFillManager.fillReport(
jasperReport, parameters, connection);

JRPdfExporter jrPdfExporter = new JRPdfExporter();


So how can i pass on the parameter value to the .jrxml


I hope i was clear with my doubt.



Sesha sai

Link to comment
Share on other sites

In your code, you have a HashMap parameters. If you want to give parameters to your jrxml, you put it in this Map like



String nameOfEmployee = "Max";
parameters.put("employee", nameOfEmployee);


before compiling/filling the report.


In your jrxml, you have to declare a parameter


<parameter name="employee" isForPrompting="false" class="java.lang.String"/>


You only have to use the same name, "employee" in Java and name="employee" in jrxml.


to use this parameter in the query, for example in the where-clause, you can write it like


select * from table where name=$P{employee}


like this, you can give the jrxml as many parameters as you want. It does not have to be a String, it only has to be an Object (Integer, Date, Long) and so on.


So, hope this helps...


Post edited by: wegnerk, at: 2007/01/12 14:02

Post edited by: wegnerk, at: 2007/01/12 14:05

Link to comment
Share on other sites

Hi I am new in this forum . But this forum helps me very much.Speciall I like thank Mr. wegnerk, Mr. seshasaib,Mr. anandharaj and all of the other members of this forum.


I have a problem. I am creating a project on java, jsp, mysql ejb etc. I am using JBoss, eclipse ,Jasper report ireport etc.. tools. Now I want to try to create build.xml file to compile with ANT . I have got a tutorial. There I saw a build.xml file . also application.xml , web.xml. If you please tell me the details of necesarry of these xml file and what is the procedure of creating those files . Actually I want to crate a war or ear file and want to deploy it inside jboss.(I want to mean where to keep which file.) I will be haighly glad to you.


Atanu Panda


Link to comment
Share on other sites

Panda ji,


My suggestion for u will be to first of all try to learn the ant scripts. Where in u will have targets and other stuf..next u need to deploy the .ear file in to c:jbossserverdefaultdeploy folder.


M not an expert in deployment process ..better search in jboss forums too in case needed.


sesha sai

Link to comment
Share on other sites

hi dear through ur comeplete discussion i learned much more about jasper reports..Dear actually whn i try to run the same code of u over here.(on my PC) i got the following error messges....more i have configured all the jars into my Classpath..............any help to get escape from this Exception i would be so thank ful to u..

Exception is ???????????????????????/

10 [main] ERROR digester.Digester - Digester.getParser:

org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/features/validation/dynamic

at gnu.xml.aelfred2.JAXPFactory.setFeature(JAXPFactory.java:102)

at org.apache.commons.digester.parser.XercesParser.configureXerces(XercesParser.java:185)

at org.apache.commons.digester.parser.XercesParser.newSAXParser(XercesParser.java:138)

at org.apache.commons.digester.ParserFeatureSetterFactory.newSAXParser(ParserFeatureSetterFactory.java:71)

at org.apache.commons.digester.Digester.getParser(Digester.java:692)

at org.apache.commons.digester.Digester.getXMLReader(Digester.java:899)

at org.apache.commons.digester.Digester.parse(Digester.java:1647)

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:238)

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:225)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:213)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:167)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:151)

at awan.ReportDriver.runReport(ReportDriver.java:79)

at awan.ReportDriver.main(ReportDriver.java:133)

Could not create the report null


thanks for ur support for this ....................

Nasir (Sr, J2SE & J2EE Application Developer)

Link to comment
Share on other sites


First of all thank you for your reply.

I am very new in iReport.


I have attached a file named test.doc. As I show in this picture

I want to create this line chart according to this values.I want to mean that in X axis there will be time from t1 -t2-t3-t4-t5 and for each time there will be specific value. Also there will be upper value and lower value limit and their corresponding line. If any value close to this upper line or lower line it will show red alert as shown in this picture.

Please any one help me.

If any one don't understand what i want please reply. [file name=test-2eb6e0b070efd73f83e242f67fac14c1.doc size=98816]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/test-2eb6e0b070efd73f83e242f67fac14c1.doc[/file]

Link to comment
Share on other sites



Actually we are developing a project with PHP and MySQL, and for reporting we surfed, we got jasper reports it should be used with ireports to generate.


We have configured ireports and the output is taken, what i need is i want to give link to my php button that it has to show the reports using the jrxml file, how to do this.


please help me, I am new to this.



Link to comment
Share on other sites


This is Atanu. I am very new in ireport and also in java environment. In the ireport I have designed a template .like this.

please look on attach file

size=150]C:Documents and SettingsAtanuMy Documentsgraph.jpeg

Now I want to plot a line graph on the basis of the each data like t1 t2 ---t5 and lcl, ucl, actual value for each row.

That I have done. Now my problem is that I have to change the color of points of t1 t2 ---t5 on the basis of Lcl and Ucl . If the value of t1 ,or t2 or ----t5 are between Ucl and Lcl the color will be blue. And if it out side of Lcl and Ucl then it will be red..

I want the following figure. Where the upper bold line is Ucl and lower bold line isLcl

size=150]C:Documents and SettingsAtanuMy Documentsdata.jpeg

Actually I have got a information that for that I have to write a customizer class for chart. Also I have write it .



Now this customize class ok running successfully with creating jar files.

Now I want to create a logic to check the value of t1 t2 t3 t5 with respect to UCL and LCL. How can I fetch data from report.

Or is there any other way to do this.

Is there any way to pass value from iReport to customizer class ?


What should I do. Please please help me. It’s urget for me.


Any help would be greatly appreciated.

Thanks in advance.

[file name=query-37ab101e3a539a71be9c962f72749d92.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-37ab101e3a539a71be9c962f72749d92.doc[/file]


Post edited by: atanupanda, at: 2007/02/06 10:06 [file name=query-c49f4d73730138a50fb4a684c3af58f4.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-c49f4d73730138a50fb4a684c3af58f4.doc[/file] size=159]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/graph-71a89926482d25dddabbf9930035c2b3.JPG

Link to comment
Share on other sites

Hi Anand,


Thanks for all ur help i am able to generate reports now based on the parameterization.


How ever i have gt another doubt now which is, In the query if at alll i want to search and then generate the report how will i pass on the param.


ex: select * from emp where ename like 'S%';


How can i do these kind of queries. I am able to generate the report based on the params passed but with complete string given in.


i.e; select * from emp where ename="sesha";

I am able to generate the report for this, but i am not able to generate the report for the above scenario.


Can u suggest me wat can be done.


Thanks and regards,

Sesha sai.

Link to comment
Share on other sites

  • 4 months later...

Hi Anand,

I am using the same procedure.but my problem is:

is this possible that if i can run the report with out any parameters (something like the wher condition in query),i am able to display the report with all countries ,now i am generating the report with a parameter in the query and i am passing the country name

as a parameter from the java by setting the valule in map.suppose in case if i didnt select any country and try to run the report ,i am getting the blank report as none of the countries was selected.but my requirement is

in such a way that if i select a country ,the report should be generated with that particular country and if i did nt select any country i should be able to display the report with all the countries as if there is no parameter at all,how can i do this.


hope i have given the problem in detail.


Thanx for the suggestions in Advance,



Link to comment
Share on other sites

Though I don't have much idea on ireport you can use one sub report on your report's summary band and give a checking on the sub report (in Print When Expression block).This subreport will be active when this parameter will be zero.


new Boolean($P{sendedParameter}==0)


Use the same query in the sub report what you have written in your master report.

I think this may give your answer.

Let me know your feedback.



Post edited by: atanupanda, at: 2007/06/19 12:21

Link to comment
Share on other sites

  • 1 year later...

Hi all,

Thanks for your discussion regarding jasper reports. Can anybody send sampel jrxml file with multiple data and multiple conditions?

For example,

I have 4 tables. table1,table2,table3,table4

I want to create report with total records of all tables . For that i want to write .jrxml file . how to do?


Thanks in advance.


- Gnaniyar Zubair


Link to comment
Share on other sites

  • 2 months later...

<%page  import="org.jfree.chart.*" %> not resolved . I get this error when i try to compile the following code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<%page  import="java.awt.*" %>
<%page  import="java.io.*" %>
<%page  import="org.jfree.chart.*" %>
<%page  import="org.jfree.chart.entity.*" %>
<%page  import ="org.jfree.data.general.*"%>
            final DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("One"new Double(43.2));
            data.setValue("Two"new Double(10.0));
            data.setValue("Three"new Double(27.5));
            data.setValue("Four"new Double(17.5));
            data.setValue("Five"new Double(11.0));
            data.setValue("Six"new Double(19.4));

            JFreeChart chart = ChartFactory.createPieChart
"Pie Chart ", data, true, true, false);

            try {
                final ChartRenderingInfo info = new 
(new StandardEntityCollection());

                final File file1 = new File("../webapps/jspchart/
                ChartUtilities.saveChartAsPNG(file1, chart, 600400, info);
            catch (Exception e) {
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <IMG SRC="piechart.png" WIDTH="600" HEIGHT="400" 
"0" USEMAP="#chart">

If any one can please tell me what all jar files have to be included. I m doing this using MyEclipse IDE and J2EE 1.4 Specification level and i have not added any JSTL support.Please help with this problem. Thanks in advance.

Link to comment
Share on other sites

  • 7 months later...


I am new Jasperreport but I have similar issue. I want to generate a child report based on where the user clicks on master report. For example my master report has emp info and child report has all emp details. I was able to add a hyperlink in the master record and this URL contians a Param1 = empname. I want to read this Param1 value in the child report. How can I do it? I have a master emp report and have links on empname. The URL contains the empname parameter


Any help is appreciated.




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