It can be easily done with small modifying of your query without programming in several ways.
Solution 1. Using single report with Barcode component in Detail band
You can use single report's template for generating several barcodes in one report.
In this case the queryString expression (works for Oracle DB) will be like this:
SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}
- it is generates a value from the sequence as many times as you need. The $P{quantity} parameter determines the number of rows (barcodes) to be generated.
The working rjxml file:
<jasperReport ...>
<parameter name="quantity" class="java.lang.Integer">
<defaultValueExpression><![CDATA[20]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
</queryString>
<field name="BARCODE" class="java.lang.Integer"/>
<field name="ROWNUM" class="java.lang.Integer"/>
<title>
<band height="82" splitType="Stretch">
<textField>
<reportElement x="145" y="18" width="240" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="47" splitType="Stretch">
<componentElement>
<reportElement x="145" y="10" width="200" height="28"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
</jasperReport>
The result will be ($P{quantity} == 5):
In your case the queryString expression will be like this:
SELECT to_char(PALLET_ID_NO_SEQ.nextval) AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}
and the expression of Barcode component will be:
new com.pepkorit.BarbecueRotateRenderer(
net.sourceforge.barbecue.BarcodeFactory.createCode128C($F{barcode}),
false, true, 1, 50, 190, 50)
Solution 2. Using Group Header band
You can use the same queryString expression as in the first solution. The group on rownum field will help us to generate single report with many barcodes belonging to its own group (one group - one barcode). The Barcode component should be placed to the Group Header band.
Using the isStartNewPage property we can manage to generate group on new page or not.
The rjxml file:
<jasperReport ...>
<parameter name="quantity" class="java.lang.Integer">
<defaultValueExpression><![CDATA[20]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
</queryString>
<field name="BARCODE" class="java.lang.Integer"/>
<field name="ROWNUM" class="java.lang.Integer"/>
<group name="rownumGroup" isStartNewPage="true">
<groupExpression><![CDATA[$F{ROWNUM}]]></groupExpression>
<groupHeader>
<band height="50">
<componentElement>
<reportElement x="145" y="11" width="200" height="28"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</groupHeader>
</group>
<title>
<band height="82" splitType="Stretch">
<textField>
<reportElement x="145" y="18" width="240" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
In case isStartNewPage="false" for group rownumGroup the result will be ($P{quantity}== 7):
In case isStartNewPage="true" for group rownumGroup the result will be ($P{quantity} == 5):
Solution 3. Using subreport
We can add Subreport component to the Detail band (see first solution) or Group Header (see second solution) band. In this case you can add to the subreport not only the Barcode component, but everything you want.