Olá a todos do GUJ.
Estou enfrentando sérios problemas com o iReports que não realiza o agrupamento de dados, mesmo eu setando aparentemente tudo certo no design.
Eu achei que o Bean que eu criei para o report estava com algum tipo de problema, mas notei que o comportamento se repete mesmo quando eu pego os dados diretamente do banco.
Criei um group no iReport e informei que a expressão do grupo era o campo "codigo_bordero", ou seja, quando este dado mudasse ele deveria criar outro agrupamento na próxima página, já que marquei como true a opção "Iniciar em nova página".
Ocorre que o campo que coloquei como expressão do do Header do grupo nunca tem seu valor alterado. E notei também que ele pega o último valor que vem ordenado no banco e o usa todas as vezes.
Como teste, pedi para ele imprimir o valor do bordero dentro do HeaderGroup e fora também (na área de details). O valor que vem impresso dentro da band Detail vem ordenado e mudando corretamente, ao passo que o valor dentro do group que é o mesmo simplesmente nunca se altera!
Segue o fonte do meu report:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="RelPrepaxBordero"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="813"
columnWidth="567"
columnSpacing="0"
leftMargin="14"
rightMargin="14"
topMargin="0"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<queryString><![CDATA[SELECT
codigo_bordero,
razao_social,
rua,
numero,
complemento,
interlocutor_1,
interlocutor_2,
interlocutor_3,
num_enc_cli
FROM
prepax_alelo
WHERE
codigo_bordero is not null
ORDER BY codigo_bordero,num_enc_cli]]></queryString>
<field name="codigo_bordero" class="java.lang.String"/>
<field name="razao_social" class="java.lang.String"/>
<field name="rua" class="java.lang.String"/>
<field name="numero" class="java.lang.String"/>
<field name="complemento" class="java.lang.String"/>
<field name="interlocutor_1" class="java.lang.String"/>
<field name="interlocutor_2" class="java.lang.String"/>
<field name="interlocutor_3" class="java.lang.String"/>
<field name="num_enc_cli" class="java.lang.String"/>
<group name="bordero" isStartNewPage="true" >
<groupExpression><![CDATA[$F{codigo_bordero}]]></groupExpression>
<groupHeader>
<band height="75" isSplitAllowed="false" >
<line direction="TopDown">
<reportElement
x="1"
y="63"
width="567"
height="1"
forecolor="#000000"
backcolor="#000000"
key="line-3"/>
<graphicElement stretchType="NoStretch">
<pen lineWidth="1.5" lineStyle="Solid"/>
</graphicElement>
</line>
<staticText>
<reportElement
x="1"
y="7"
width="127"
height="19"
key="staticText-47"/>
<box></box>
<textElement verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[NÚMERO DO BORDERÔ:]]></text>
</staticText>
<textField isStretchWithOverflow="false" pattern="dd/MM/yyyy" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="128"
y="7"
width="129"
height="19"
key="textField-29"/>
<box></box>
<textElement verticalAlignment="Middle">
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{codigo_bordero}]]></textFieldExpression>
</textField>
<line direction="TopDown">
<reportElement
x="1"
y="31"
width="567"
height="1"
forecolor="#000000"
backcolor="#000000"
key="line-4"/>
<graphicElement stretchType="NoStretch">
<pen lineWidth="1.5" lineStyle="Solid"/>
</graphicElement>
</line>
<staticText>
<reportElement
x="126"
y="37"
width="158"
height="19"
key="staticText-51"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[NÚMERO DE AR]]></text>
</staticText>
<staticText>
<reportElement
x="387"
y="37"
width="158"
height="19"
key="staticText-52"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[CÓDIGO DE BARRAS]]></text>
</staticText>
<staticText>
<reportElement
x="1"
y="37"
width="109"
height="19"
key="staticText-54"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[SEQUENCIAL]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="0" isSplitAllowed="true" >
</band>
</groupFooter>
</group>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="0" isSplitAllowed="false" >
</band>
</title>
<pageHeader>
<band height="72" isSplitAllowed="true" >
<staticText>
<reportElement
x="1"
y="44"
width="63"
height="19"
key="staticText-42"/>
<box></box>
<textElement verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[OPERADOR:]]></text>
</staticText>
<textField isStretchWithOverflow="false" pattern="dd/MM/yyyy" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="64"
y="44"
width="146"
height="19"
key="textField-25"/>
<box></box>
<textElement verticalAlignment="Middle">
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{interlocutor_1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement
x="139"
y="6"
width="303"
height="25"
key="staticText-26"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="12" isBold="true"/>
</textElement>
<text><![CDATA[PREPAX ALELO - BORDERÔ]]></text>
</staticText>
<staticText>
<reportElement
x="347"
y="44"
width="83"
height="19"
key="staticText-53"/>
<box></box>
<textElement verticalAlignment="Middle">
<font fontName="Arial" pdfFontName="Helvetica-Bold" size="10" isBold="true"/>
</textElement>
<text><![CDATA[IMPRESSO EM:]]></text>
</staticText>
<textField isStretchWithOverflow="false" pattern="dd/MM/yyyy" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="430"
y="44"
width="131"
height="19"
key="textField-33"/>
<box></box>
<textElement verticalAlignment="Middle">
<font/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="0" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="453" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="128"
y="1"
width="156"
height="21"
key="textField-13"/>
<box></box>
<textElement textAlignment="Center">
<font fontName="Arial" size="10"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{num_enc_cli}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="1"
y="1"
width="109"
height="21"
key="textField-34"/>
<box></box>
<textElement textAlignment="Center">
<font fontName="Arial" size="10"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{bordero_COUNT}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="387"
y="4"
width="158"
height="21"
key="textField-35"/>
<box></box>
<textElement textAlignment="Center">
<font fontName="Arial" size="10"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{codigo_bordero}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="0" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
Em anexo segue como ele gera o PDF.
Note que dentro do group ele imprime o valor "[telefone removido]", que é exatamente o último valor que o banco traz na ordenação. Ao passo que fora do group, na band Detail, o report obedece a ordenação da query corretamente.
O que pode estar acontecendo?
Obrigado!
