Page Break error new page - jasper-reports

Print a set of invoices in PDF, I put Page Break $V{PAGE_COUNT}==16 and a group to break invoice number. All OK, but if the invoice rows = 16 the group total invoice print in a new page. Any ideas?
<group name="documento" isResetPageNumber="true" footerPosition="ForceAtBottom"><groupExpression><numero fattura></groupExpression><groupFooter> <band height="230" splitType="Immediate"><textField><reportElement> totali fattura.....</band></groupFooter></group> <pageHeader><band height="350" splitType="Stretch"> <textField><reportElement><textField><reportElement>testata fattura</band></pageHeader><detail><band height="16" splitType="Stretch"><break> <reportElement><printWhenExpression><![CDATA[$V{PAGE‌​_COUNT}==16]]></printWhenExpression> </reportElement></break></band></detail></ja‌​sperReport>

Related

Jasper CVC Component with Sub-Dataset

I'm working on CVC component in Jasper Studio. It is working fine with the "ReportMainDataset" but when I'm using the "Sub Dataset" it is not plotting.
Just wanted to know does CVC component works with "Sub Dataset" or not. If works, guide me how can I achieve this.
The tag for indicating the dataset is <cvData>
Example
subdataset
<subDataset name="Dataset1" uuid="03d50d7f-1b96-486a-ac64-7d2c6e440433">
<queryString>
<![CDATA[select count(*) t, shipcountry, shipcity from orders group by shipcountry, shipcity order by shipcountry, shipcity]]>
</queryString>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<field name="T" class="java.lang.Long"/>
<field name="SHIPCITY" class="java.lang.String"/>
</subDataset>
component
<cvc:customvisualization xmlns:cvc="http://www.jaspersoft.com/cvcomponent" xsi:schemaLocation="http://www.jaspersoft.com/cvcomponent http://www.jaspersoft.com/cvcomponent/component.xsd" evaluationTime="Report" onErrorType="Icon">
<cvc:itemProperty name="script" value="d3_zoomable_circle_packing.min.js"/>
<cvc:itemProperty name="css" value="d3_zoomable_circle_packing.css"/>
<cvc:cvData>
<dataset>
<datasetRun subDataset="Dataset1" uuid="bd23d50f-2149-4985-a0ac-883505172688">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<cvc:item>
<cvc:itemProperty name="category">
<valueExpression><![CDATA[$F{SHIPCOUNTRY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="subcategory">
<valueExpression><![CDATA[$F{SHIPCITY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="value">
<valueExpression><![CDATA[$F{T}]]></valueExpression>
</cvc:itemProperty>
</cvc:item>
</cvc:cvData>
</cvc:customvisualization>
EDIT: As #dada67 comment it does not seem to work properly, I have also test it with sample d3_zoomable_cricle_packing.jrxml without success, this is the bug issue
The work around, create a subreport!

How to show dropdown in excel using jrxml (jasper api)?

I am new to jasper . My project used jasper to create an excel template that has only column names (eg : Name , Age , Department , Location) which uses jrxml for fonts and alignment. [basically we used the for showing the column names]
User can download the template and they can enter the values they want.
Now in order to avoid user enter the details manually by entering values , I would like to give dropdowns in the template with some hard coded values .
For example for the field 'Location' , I can set values like 'Texas' , 'California', 'FortWorth' etc . I am not querying from DB for these values , I just want to hard code these in .jrxml . I have to create one more row where the Location column alone should have drop down values from which user can pick one and upload to my application
In the downloaded excel , I want a dropdown with the above values so that user can select instead of typing themselves.
Is there any way to put this in .jrxml . If that is not possible then give the code that can render these in a dropdown in excel.
My sample .jrxml for one field is
<staticText>
<reportElement mode="Opaque" x="684" y="0" width="114" height="20" backcolor="#808080">
</reportElement>
<box leftPadding="10">
<pen lineColor="#000000" />
<topPen lineWidth="0.5" />
<leftPen lineWidth="0.5" />
<bottomPen lineWidth="0.5" />
<rightPen lineWidth="0.5" />
</box>
<textElement>
<font size="10" isBold="true" />
</textElement>
<text><![CDATA[Location]]></text>
</staticText>
Please let me know if more details are required
I don't think that with current jasper api 6.0 this is possibile but with POI (that is already in your classpath) it is farily easy to add this after export.
First we export or JasperPrint print, to excel (include code since its best to remove empty rows, we will process with poi later, Exception handling is beyond this example)
JRXlsExporter exporter = new JRXlsExporter();
File outputFile = new File("excelTest.xls");
exporter.setExporterInput(new SimpleExporterInput(print));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
configuration.setWhitePageBackground(false);
configuration.setRemoveEmptySpaceBetweenColumns(true);
configuration.setRemoveEmptySpaceBetweenRows(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
Now that the report is exported to excel, we re-open it with POI and add our data validation.
int rowCount = 50; //This will be discussed at end.
int cellWithDV = 1;
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(outputFile));
HSSFSheet sheet = workbook.getSheetAt(0);
CellRangeAddressList addressList = new CellRangeAddressList(1,rowCount, cellWithDV, cellWithDV);
DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(
new String[]{ "Texas" , "California", "FortWorth"});
DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint);
dataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(dataValidation);
workbook.write(new FileOutputStream(outputFile));
workbook.close();
The rowCount can be achived by:
Querying the database again
Use a scriptlet that counts how many times beforeDetailEval() is called
Use POI to find the the last row.
Use maximum value in excel (2003) is 65536
Hope this helps

How to create user defined formula for user defined field

I have created one JasperReports report in iReport 4.5.0.
Here i have created one expression as:
<textField pattern="###0.0;-###0.0">
<reportElement x="248" y="3" width="46" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[( $F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) )]]></textFieldExpression>
</textField>
Here I need the sum(total) of this text field created above ,
How to do that?
In this case you would simply create a variable with the same expression, but with a operation of "SUM". You can change the reset type to specify a group or simply for the whole report.
You can then use that variable in the Text Field element, with the execution time of Report/Group/Now depending on your needs.
<variable name="SOSUM" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) ]]></variableExpression>
</variable>

Passing main parameter to sub-datasets in JasperStudio

i'm created a report with JasperStudio 5.5 that have many parameter defined in the main and a lot of sub-dataset (defined with tables) that required this parameters.
The situation:
/main/Parameters: myPar
/main/mySubDataSet1/
/main/mySubDataSet2/
...
/main/mySubDataSetN/
The sub-dataset need to use this parameter in her query: select * from Tab t where t.attr = $P!{myPar}
So, my problem is that the sub-dataset can't access at this main paramenter, all the time that i try compiled, the program send me "Parameter not found : myPar".
How i can do for use myPar in the sub-dataset?
p.s.: i read this thread Pass main dataset parameter to subdataset query (based on iReport) but without success...
Well, you need to fill subDataset parameters with values where you actually make use of them. In this case the table which lists items from your subDataset needs to declare the necessary parameters and assign the values of the report-level dataset parameters to them.
In jrxml it sounds:
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="mySubDataSet1" uuid="bbe7937c-a8f1-4838-811a-3f11ec1f8e35">
<datasetParameter name="myPar">
<datasetParameterExpression><![CDATA[$P{myPar}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
...
</jr:table>
For detail:
<subDataset name="dsLines" uuid="a47307ff-90a8-476f-afd1-0fd8aa0517d0">
<parameter name="formalId" class="java.lang.String"/>
<queryString language="SQL">
<![CDATA[
SELECT s.formalid, sl.*
FROM salesorder s INNER JOIN salesorderline sl
ON (s.id = sl.salesorder_id)
WHERE s.formalid = $P{formalId}
]]>
</queryString>
<field name="qty" class="java.math.BigDecimal"/>
...
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="dsLines" uuid="3ef5ec78-ab18-4f44-88e6-f99f3eafac07">
<datasetParameter name="formalId">
<datasetParameterExpression><![CDATA[$F{formalid}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="29" uuid="f675a273-7ea6-4bd4-8a55-c7522dfea2a8">
...

group expression in jasper reports

I've a report which has a has 5 columns on each page and I have a group defined which shows columns related to
A | B | C | D | E - main column
X | Y | Z - group - A is the key
I have my query ORDER BY A, but when it is displayed it doesn't print the results in next page if A is changed.
Following is how I have a group defined.
<group name="A" isResetPageNumber="true" >
<groupExpression><![CDATA[$F{A}]]></groupExpression>
<groupHeader>
<band/>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
does A need to be part of the group?
Use:
<group name="A" isStartNewPage="true" isReprintHeaderOnEachPage="true"
isResetPageNumber="false" >
I answered my own question. I had to add A with X, Y, and Z in order for group to work.