Detailed sub-report bar not showing

My main report contains 5 fields, 4 of them are of type java.lang.String , and the last is of type java.util.List . I used it as a data source for the subtitle. I set the data source in the subtitle.

Subreport Properties:

Connection Type: Use Data Source Expression
Data source expression: new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource file ($ F {Field5})

Data transfer is working fine (I think) because when I populate a report inside a Java application. I can view the data transferred to fields 1 through 4, but at first I cannot check in field 5, because the subreport does not display data, but only static texts defined in the column heading.

Then, when I placed the sub-report fields in the footer of the page, I found out that the data was transferred successfully, the problem is that the Detail group itself is not displayed.

Why is this not displayed?

In the subreport properties I have:

If no data: All sections, without details

Please shed some light on this.

+7
source share
5 answers

I had the same problem for more than 1 day. In the application I'm developing, there are several JasperReports that work. I ran into this problem when adding a new one. No matter what I tried, nothing is displayed in the Detail group. I tried everything from triple checking the controller that populates the report, to jasperreports to the latest version of jasperreports and the latest version of iReports . Nothing seemed to work.

The problem is that the default message is: When No Data: All Sections, No Detail , which basically means that if no data is sent to the report, it displays all the sections except the detailed one.

Although in addition to the static text that I used to test the report, I passed parameters directly from the Java controller, but it did not work until I added the EXEC [myFunction] $P{parameterId} property to the Query Text property of the report. The function is simple, simple, which takes parameterId passed from Java as a parameter and returns something. (also make sure that you set the language for the sql sql query sql query).

To summarize, for some reason, the report does not seem to perceive Java parameters as data (therefore, it displays all sections except Detail), therefore, when I explicitly call the SQL function, which returns some parameters and places them on my details page, it works.

I hope this helps you, I spent my head 10 hours to figure it out.

+11
source

You can try this sample.

POJO (Bean):

 public class BeanWithList { private List<String> m_cities; private Integer m_id; public BeanWithList(List<String> cities, Integer id) { m_cities = cities; m_id = id; } public List<String> getCities() { return m_cities; } public Integer getId() { return m_id; } } 

Code for filling out the report:

 public static void testBuildPdf() { try { Map<String, Object> params = new HashMap<String, Object>(); params.put("BeanSubreport", JasperCompileManager.compileReport(subreportSource)); JasperReport jasperReport = JasperCompileManager.compileReport(masterSource); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource()); JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName); } catch (Exception e) { e.printStackTrace(); } } private static JRDataSource getDataSource() { Collection<BeanWithList> coll = new ArrayList<BeanWithList>(); BeanWithList bean = new BeanWithList(Arrays.asList("London", "Paris"), 1); coll.add(bean); bean = new BeanWithList(Arrays.asList("London", "Madrid", "Moscow"), 2); coll.add(bean); bean = new BeanWithList(Arrays.asList("Rome"), 3); coll.add(bean); return new JRBeanCollectionDataSource(coll); } 

Jrxml sub-register:

 <?xml version="1.0" encoding="UTF-8"?> <jasperReport .. leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"> <field name="city" class="java.lang.String"> <fieldDescription><![CDATA[_THIS]]></fieldDescription> </field> <detail> <band height="20" splitType="Stretch"> <textField> <reportElement positionType="Float" x="0" y="0" width="100" height="20"/> <box leftPadding="10"> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement/> <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression> </textField> </band> </detail> </jasperReport> 

Jrxml wizard:

 <?xml version="1.0" encoding="UTF-8"?> <jasperReport ...> <parameter name="BeanSubreport" class="net.sf.jasperreports.engine.JasperReport"/> <field name="id" class="java.lang.Integer"/> <field name="cities" class="java.util.Collection"/> <title> <band height="103" splitType="Stretch"> <staticText> <reportElement x="138" y="28" width="258" height="20"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="true" isItalic="true"/> </textElement> <text><![CDATA[Bean with List sample]]></text> </staticText> </band> </title> <columnHeader> <band height="20"> <staticText> <reportElement x="0" y="0" width="100" height="20"/> <box> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="true" isItalic="true" isUnderline="false"/> </textElement> <text><![CDATA[Id]]></text> </staticText> <staticText> <reportElement x="100" y="0" width="100" height="20"/> <box> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="true" isItalic="true" isUnderline="false"/> </textElement> <text><![CDATA[City name]]></text> </staticText> </band> </columnHeader> <detail> <band height="20" splitType="Stretch"> <textField> <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/> <box leftPadding="10"> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement/> <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> </textField> <subreport> <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="100" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{cities})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{BeanSubreport}]]></subreportExpression> </subreport> </band> </detail> </jasperReport> 

The result will be:

The report in PDF format


The main trick of this example is to use the _THIS variable _THIS "

For more information, you can read JavaBean Data Sources .

+1
source

I solved this by setting the submission parameter at runtime.

For those facing the same problem, I just saved the JasperReport object (datatype is net.sf.jasperreports.engine.JasperReport ) in a java variable, and then passed the variable to the parameter inside the report. This parameter is set to Report Expression . The subordination parameter expression class must be net.sf.jasperreports.engine.JasperReport .

0
source

When you pass parameters to FillManager, don't use null, use JREmptyDataSource.

The correct way: JasperFillManager.fillReport (this.getReportTemplate (JASPER_REPORT_EXPIRY_LETTER), this.parameters, new JREmptyDataSource ());

Incorrect: JasperFillManager.fillReport (this.getReportTemplate (JASPER_REPORT_EXPIRY_LETTER), this.parameters, null);

0
source
 import java.awt.Desktop; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.xml.JRXmlLoader; import net.sf.jasperreports.swing.JRViewer; import net.sf.jasperreports.view.JasperViewer; public class MyForm extends JFrame { public static JasperDesign jasperDesign; public static JasperPrint jasperPrint; public static JasperReport jasperReport; static JRBeanCollectionDataSource jrBeanCollectionDataSource; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { MyForm frame = new MyForm(); frame.setVisible(true); } }); } /** * Create the frame. */ public MyForm() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 431, 286); setTitle("ThaiCreate.Com Java GUI Tutorial"); getContentPane().setLayout(null); // Button Report JButton btnOpenReport = new JButton("Open Report"); btnOpenReport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Connection connect = null; try { Class.forName("com.mysql.jdbc.Driver"); connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test" ,"root",""); System.out.println("Connected...."); } catch (ClassNotFoundException e1) {e1.printStackTrace();} catch (SQLException e) {e.printStackTrace();} // Application path FileInputStream report = null; try { FileInputStream input = new FileInputStream(new File("C:\\Users\\admin\\Desktop\\report1.jrxml")); try { jasperDesign = JRXmlLoader.load(input); jasperReport = JasperCompileManager.compileReport(jasperDesign); jasperPrint = JasperFillManager.fillReport(jasperReport, null, connect); JasperExportManager.exportReportToPdfFile(jasperPrint, "E:\\demo.pdf"); // Desktop.getDesktop().open(new File("D:/ReceiptReport.pdf")); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JFrame frame = new JFrame(); frame.setTitle("ThaiCreate.Com Customer Report"); frame.setBounds(100, 100, 800,600); frame.getContentPane().add(new JRViewer(jasperPrint)); frame.setVisible(true); try { connect.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnOpenReport.setBounds(137, 98, 146, 23); getContentPane().add(btnOpenReport); setResizable (false); } } 
0
source

All Articles