Jump to content
Changes to the Jaspersoft community edition download ×

Generate report with nested object problem


Recommended Posts

I have a class with nested object. I'm using Bean Collection DataSource. 

 

Here is the class of the Transaction bean

public class Transaction {    private Long idTransaction;    private String observation;    private String observation2;    private DirectionOfTransaction directionOfTransaction;    private LocalDateTime dateTime;    private Account account;    private User user;    private TypeOfTransaction typeOfTransaction;    public Long getIdTransaction() {        return idTransaction;    }    public void setIdTransaction(Long idTransaction) {        this.idTransaction = idTransaction;    }    public String getObservation() {        return observation;    }    public void setObservation(String observation) {        this.observation = observation;    }    public String getObservation2() {        return observation2;    }    public void setObservation2(String observation2) {        this.observation2 = observation2;    }    public DirectionOfTransaction getDirectionOfTransaction() {        return directionOfTransaction;    }    public void setDirectionOfTransaction(DirectionOfTransaction directionOfTransaction) {        this.directionOfTransaction = directionOfTransaction;    }    public LocalDateTime getDateTime() {        return dateTime;    }    public void setDateTime(LocalDateTime dateTime) {        this.dateTime = dateTime;    }    public Account getAccount() {        return account;    }    public void setAccount(Account account) {        this.account = account;    }    public User getUser() {        return user;    }    public void setUser(User user) {        this.user = user;    }    public TypeOfTransaction getTypeOfTransaction() {        return typeOfTransaction;    }    public void setTypeOfTransaction(TypeOfTransaction typeOfTransaction) {        this.typeOfTransaction = typeOfTransaction;    }}[/code]

I have problem in JasperSoft community edition. first of all insert my class folder with in class path.

Get Transaction class properties, when i drag & drop field with type like Strin, bigDecimal, to the details section every thing works fine.

But when i drag and drop field declared with custom types like DirectionOfTransaction, Account ..etc (My own class), Japsersoft sutdio can't place them in the details section.

I have also create a variable using some with conditional expression and place in the detail section i get an error:

Here is hte JRXML file:

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.2.2.final using JasperReports Library version 6.2.2  --><!-- 2016-06-11T18:35:06 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="secondReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4a30fc90-411a-46d8-b4f3-ba259634b3cc">   <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>   <queryString>      <![CDATA[]]>   </queryString>   <field name="directionOfTransaction" class="bean.DirectionOfTransaction"/>   <field name="observation" class="java.lang.String"/>   <variable name="dirVar" class="java.lang.String">      <variableExpression><![CDATA[((DirectionOfTransaction) $F{directionOfTransaction}).equals(DirectionOfTransaction.CREDIT)) ? "CREDIT" : "DEBIT"]]></variableExpression>   </variable>   <background>      <band splitType="Stretch"/>   </background>   <title>      <band height="79" splitType="Stretch"/>   </title>   <pageHeader>      <band height="35" splitType="Stretch"/>   </pageHeader>   <columnHeader>      <band height="61" splitType="Stretch">         <staticText>            <reportElement x="171" y="0" width="100" height="30" uuid="b8ac6d0b-e915-4f42-8f8d-b96378dae6bf"/>            <text><![CDATA[observation]]></text>         </staticText>      </band>   </columnHeader>   <detail>      <band height="48" splitType="Stretch">         <textField>            <reportElement x="171" y="18" width="100" height="30" uuid="43d5b9f4-5602-4987-b944-1bd1cd0776de"/>            <textFieldExpression><![CDATA[$F{observation}]]></textFieldExpression>         </textField>      </band>   </detail>   <columnFooter>      <band height="45" splitType="Stretch"/>   </columnFooter>   <pageFooter>      <band height="54" splitType="Stretch"/>   </pageFooter>   <summary>      <band height="42" splitType="Stretch"/>   </summary></jasperReport>[/code]

and her is the code for java program:

 

try {    InputStream inputStream = new FileInputStream("./report/secondReport.jrxml");    JasperDesign jasperDesign = JRXmlLoader.load(inputStream);    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);    HashMap parameter = new HashMap();    JRDataSource beanDataSource = new JRBeanCollectionDataSource(transactionModel.getTransactionList());    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, beanDataSource);    if (jasperPrint != null) {        JasperViewer.viewReport(jasperPrint);        System.out.println("Printed");    } else        System.out.println("Not able to print");} catch (FileNotFoundException e) {    e.printStackTrace();} catch (JRException e) {    e.printStackTrace();}[/code]

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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