473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create dynamic report through JRXML???

13 New Member
Hey! I am working on jrxml to create dynamic re0ports. I have parameterized the columns i.e. the jrxml for that report can be used to generate other reports as well.

However, i have not managed to make the fields flexible. That is, if the user selects 4 columns it would work but if 1 or 2 or 3 columns are selected, it gives an error since the field names are unidentified.

Please post a solution urgently if something like a default expression for fieldname can be created or a for loop/java script can be used.

Moreover, how can jasper designer be exactly used to achieve this?

The jrxml is as follows:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <!DOCTYPE jasperReport
  3.   PUBLIC "-//JasperReports//DTD Report Design//EN"
  4.   "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
  5.  
  6. <jasperReport name="report1">
  7.  
  8.     <parameter name="reportTitle" class="java.lang.String"/>
  9.     <parameter name="author" class="java.lang.String"/>
  10.     <parameter name="startDate" class="java.lang.String"/>
  11.  
  12.  <parameter name="C1" class="java.lang.String">
  13.         <defaultValueExpression>
  14.             new java.lang.String("")
  15.         </defaultValueExpression>
  16.     </parameter>
  17.  
  18.     <parameter name="C2" class="java.lang.String">
  19.         <defaultValueExpression>
  20.             new java.lang.String("")
  21.         </defaultValueExpression>
  22.     </parameter>
  23.  
  24.     <parameter name="C3" class="java.lang.String">
  25.         <defaultValueExpression>
  26.             new java.lang.String("")
  27.         </defaultValueExpression>
  28.     </parameter>
  29.  
  30.     <parameter name="C4" class="java.lang.String">
  31.         <defaultValueExpression>
  32.             new java.lang.String("default parameter value")
  33.         </defaultValueExpression>
  34.     </parameter>
  35.  
  36.     <field name="COLUMN_1" class="java.lang.Integer"/>
  37.     <field name="COLUMN_2" class="java.lang.Integer"/>
  38.     <field name="COLUMN_3" class="java.lang.Integer"/>
  39.     <field name="COLUMN_4" class="java.lang.Integer"/>
  40.  
  41.     <title>
  42.         <band height="60">
  43.             <textField>
  44.                 <reportElement x="0" y="10" width="500" height="40"/>
  45.                 <textElement textAlignment="Center">
  46.                     <font size="24"/>
  47.                 </textElement>
  48.                 <textFieldExpression class="java.lang.String">
  49.                     <![CDATA[$P{reportTitle}]]>
  50.                 </textFieldExpression>
  51.             </textField>
  52.             <textField>
  53.                 <reportElement x="0" y="40" width="500" height="20"/>
  54.                 <textElement textAlignment="Center"/>
  55.                 <textFieldExpression class="java.lang.String">
  56.                     <![CDATA["Run by: " + $P{author}
  57.                         + " on " + $P{startDate}]]>
  58.                 </textFieldExpression>
  59.             </textField>
  60.         </band>
  61.     </title>
  62.  
  63.  
  64. <columnHeader>
  65.         <band height="30">
  66.             <rectangle>
  67.                 <reportElement x="0" y="0" width="500" height="25"/>
  68.                 <graphicElement/>
  69.             </rectangle>
  70.  
  71.             <textField>
  72.                 <reportElement x="0" y="5" width="170" height="15"/>
  73.                 <textFieldExpression class="java.lang.String">
  74.                     <![CDATA[$P{C1}]]>
  75.                 </textFieldExpression>
  76.             </textField>
  77.  
  78.             <textField>
  79.                 <reportElement x="70" y="5" width="170" height="15"/>
  80.               <textFieldExpression class="java.lang.String">
  81.                     <![CDATA[$P{C2}]]>
  82.                 </textFieldExpression>
  83.             </textField>
  84.  
  85.             <textField>
  86.                 <reportElement x="150" y="5" width="150" height="15"/>
  87.               <textFieldExpression class="java.lang.String">
  88.                     <![CDATA[$P{C3}]]>
  89.                 </textFieldExpression>
  90.             </textField>
  91.  
  92.             <textField>
  93.                 <reportElement x="300" y="5" width="150" height="15"/>
  94.               <textFieldExpression class="java.lang.String">
  95.                     <![CDATA[$P{C4}]]>
  96.                 </textFieldExpression>
  97.  
  98.             </textField>
  99.  
  100.  
  101.             </band>
  102.     </columnHeader>
  103.  
  104.  
  105. <detail>
  106.         <band height="20">
  107.  
  108.             <textField>
  109.                 <reportElement x="5" y="0" width="50" height="15"/>
  110.                 <textElement/>
  111.                 <textFieldExpression class="java.lang.Integer">
  112.                     <![CDATA[$F{COLUMN_1}]]>
  113.                 </textFieldExpression>
  114.             </textField>
  115.  
  116.             <textField>
  117.                 <reportElement x="90" y="0" width="150" height="15"/>
  118.                 <textElement/>
  119.                 <textFieldExpression class="java.lang.Integer">
  120.                     <![CDATA[$F{COLUMN_2}]]>
  121.                 </textFieldExpression>
  122.             </textField>
  123.  
  124.             <textField>
  125.                 <reportElement x="170" y="0" width="50" height="15"/>
  126.                 <textElement/>
  127.                 <textFieldExpression class="java.lang.Integer">
  128.                     <![CDATA[$F{COLUMN_3}]]>
  129.                 </textFieldExpression>
  130.             </textField>
  131.  
  132.             <textField>
  133.                 <reportElement x="320" y="0" width="150" height="15"/>
  134.                 <textElement/>
  135.                 <textFieldExpression class="java.lang.Integer">
  136.                     <![CDATA[$F{COLUMN_4}]]>
  137.                 </textFieldExpression>
  138.             </textField>
  139.  
  140.         </band>
  141.     </detail>
  142.  
  143. </jasperReport> 
Dec 20 '09 #1
1 9638
Ricardo Mariaca
1 New Member
I recommend to use DynamicReports, is open source and you can create dynamic reports very easy
Apr 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
17514
by: Climber | last post by:
Hello, I want to now how to do a dynamic report with Crystal Report (C# .Net), the number of colum and row are different each time because they depend of my data base. Thanks Climber
0
3662
by: Benny | last post by:
Hello Experts, Currently Im working on a web application using asp.net with C#. I need to create a report depends on user's selection of the database fields, i.e. the user may want to display...
6
4803
by: Peter Herath | last post by:
I want to create a dynamic report using a crosstab query...... pls someone look into my attached example database and help me out to do the report generation.... example is like dis...: there...
2
1704
by: zoro25 | last post by:
Hi, I want to create a dynamic report and for that I'm using a very simple Combo Box (only one item) and I want to use this filter on my report. Here's the code I came up with: Private Sub...
0
1149
by: josur | last post by:
Hi, I would like to know if is possible to create dynamic reports based on cubes. What i mean is,after creating a cube with a couple of dimensions and measure if is there any way to give the...
3
18680
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
4
2679
by: Sep410 | last post by:
Hi all, I have to create a dynamic report in vb.net. I never had done something like this before.Users want to see tables name and when they choose the table they will select which fields should...
2
8712
by: J360 | last post by:
I'm using VB in Access 2003 to generate a dynamic report. I first open the report in design view to set all the grouping levels etc. I then use with rpt .printer.orientation =...
5
3222
by: Mr Key | last post by:
Hi, I hope someone could help me on this, I have a query of several fields from which I want to create report of few fields selected by user. Say total fields be 30 as Field1...Field30, The first...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.