Subrelatorio com IReport em branco

3 respostas
agcp123

Estou criando uma applicação utilizando Struts2 e para emissao de relatorios estou utilizando Servlet para enviar algumas informações para o arquivo .jasper
O problema é quando tento chamar o relatório pela minha aplicacao, assim, ele mostra somente as informações do relatorio e mostra o subrelatorio em branco sem nenhuma informação…
Estou com esse problema a quase uma semana e nao estou conseguindo resolve-lo.
Alguem tem alguma sugestao de como posso solucionar este problema??

Procurei em outros Tópicos do fórum e achei diversas pessoas com o mesmo problema… mas nenhuma resposta concreta de como resolver…

3 Respostas

rdmardegam

Como você está chamando seu subrelatorio? Oque voce passa ao seu subrelatorio?

Teria o condigo?

agcp123

Chamo o relatorio atravez de um servlet mapeado passando como paramentro a string "pagina=atendimento" para reconhecer qual relatorio estou fazenod referencia
Ao abrir o relatorio, algumas informaçoes aparecem.. mas os subrelatorios nao..

protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		try {
			/** Conecta com o banco * */
			Connection con = DriverManager.getConnection(url, user, password);
			/** Retorna o caminho relativo do servlet**/
			ServletContext context = getServletContext();
			
			
			/** Define os parametros usados no relatorio * */
			Map parameters = new HashMap();
			
			if (request.getParameter("pagina").equalsIgnoreCase("atendimento")) {
				
				/** Indica o arquivo jasper, o arquivo pdf e a página de retorno após terminar**/
				JasperStr = "relatorioAtendimento.jasper";
				ArquivoPDF = "relatorioAtendimento.pdf";
				RedirectStr = "http://localhost:8080/TIB2/getPageAtendimento.action";
				
				/** Monta a consulta sql basica para retornar todos os registros de Atendimentos **/
				query = "select DISTINCT p.idpessoa, p.tipopessoa " +
						" FROM Atendimento atd, Pessoa p, ProjetoAtendimento proj, Setor setor " +
						" where " +
						" atd.isativo = true" +
						" and atd.pessoa = p.idpessoa " +
						" and atd.projeto = proj.idprojetoatendimento " +
						" and atd.setorresponsavel = setor.idsetor";
								
				/** Adiciona ao sql, comparações referentes a pesquisa na pagina.
				 *  Para cada campo da pesquisa é passado um parâmetro no link.
				 **/
								
				pathJasper = context.getRealPath("WEB-INF/classes/tib/relatorio/")+ "/atendimentoPJ.jasper";
				parameters.put("SUBREPORT_DIR", pathJasper + File.separator);
								
				
			}
			
			
			/** Executa a consulta e retorna em um ResultSetDataSource 
			 *  que servirá de parâmetro para a geração do arquivo pdf
			 **/
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(query);
			JRResultSetDataSource jrRS = new JRResultSetDataSource( rs );

			/** Gera o arquivo pdf apartir do jasper * */
			//JasperRunManager.runReportToPdfFile(PathStr + JasperStr, parameters, jrRS);
			

			ByteArrayOutputStream baos = new ByteArrayOutputStream();   
			JasperReport relatorio = (JasperReport) JRLoader.loadObject(context.getRealPath("WEB-INF/classes/tib/relatorio/"+ JasperStr)); 
			//JasperReport relatorio = (JasperReport) JRLoader.loadObject(PathStr + JasperStr);
			baos.write(JasperRunManager.runReportToPdf(relatorio, parameters, jrRS));	

....
Segue tbm o arquivo .jrxml do relatorio
<?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="relatorioAtendimento"
		 columnCount="1"
		 printOrder="Vertical"
		 orientation="Portrait"
		 pageWidth="595"
		 pageHeight="842"
		 columnWidth="535"
		 columnSpacing="0"
		 leftMargin="30"
		 rightMargin="30"
		 topMargin="20"
		 bottomMargin="20"
		 whenNoDataType="AllSectionsNoDetail"
		 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.*" />

	<parameter name="PathImagem" isForPrompting="false" class="java.lang.String"/>
	<parameter name="SUBREPORT_DIR" isForPrompting="false" class="java.lang.String">
		<defaultValueExpression ><![CDATA["/"]]></defaultValueExpression>
	</parameter>
	<parameter name="pathJasper" isForPrompting="false" class="java.lang.String"/>
	<queryString><![CDATA[select DISTINCT p.idpessoa as idpessoa, p.tipopessoa  FROM Atendimento atd, Pessoa p, ProjetoAtendimento proj, Setor setor 
where  atd.isativo = true and atd.pessoa = p.idpessoa  and atd.projeto = proj.idprojetoatendimento  and atd.setorresponsavel = setor.idsetor]]></queryString>

	<field name="idpessoa" class="java.lang.Integer"/>
	<field name="tipopessoa" class="java.lang.String"/>

		<background>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</background>
		<title>
			<band height="1"  isSplitAllowed="true" >
			</band>
		</title>
		<pageHeader>
			<band height="53"  isSplitAllowed="true" >
				<line direction="TopDown">
					<reportElement
						x="0"
						y="51"
						width="534"
						height="0"
						key="line-2"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<image  scaleImage="RetainShape" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="4"
						y="1"
						width="530"
						height="50"
						key="image-1"/>
					<box></box>
					<graphicElement stretchType="NoStretch"/>
					<imageExpression class="java.lang.String"><![CDATA["C:\\Arquivos de programas\\workspaceAugusto\\TIB2\\src\\tib\\relatorio\\imagemCabecalho.jpg"]]></imageExpression>
				</image>
			</band>
		</pageHeader>
		<columnHeader>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnHeader>
		<detail>
			<band height="214"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="154"
						y="12"
						width="161"
						height="14"
						key="textField-1"/>
					<box></box>
					<textElement>
						<font/>
					</textElement>
				<textFieldExpression   class="java.lang.Integer"><![CDATA[$F{idpessoa}]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement
						x="0"
						y="12"
						width="148"
						height="21"
						key="staticText-1"/>
					<box></box>
					<textElement>
						<font/>
					</textElement>
				<text><![CDATA[Atendimento : ]]></text>
				</staticText>
				<elementGroup><!--  Start: 1 !-->
				<subreport  isUsingCache="false">
					<reportElement
						mode="Transparent"
						x="0"
						y="38"
						width="512"
						height="133"
						key="subreport-1"
						positionType="Float"
						isPrintWhenDetailOverflows="true"/>
					<subreportParameter  name="idpessoa">
						<subreportParameterExpression><![CDATA[$F{idpessoa}]]></subreportParameterExpression>
					</subreportParameter>
					<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
					<subreportExpression  class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + ($F{tipopessoa}.trim().equals("F") ? "atendimentoPF.jasper" : "atendimentoPJ.jasper")]]></subreportExpression>
				</subreport>
				</elementGroup><!-- End 1 !-->
			</band>
		</detail>
		<columnFooter>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</columnFooter>
		<pageFooter>
			<band height="17"  isSplitAllowed="true" >
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="329"
						y="4"
						width="166"
						height="12"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box>					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
					<textElement textAlignment="Right">
						<font fontName="Times New Roman" pdfFontName="Times-Roman" size="10"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["¡gina " + $V{PAGE_NUMBER} + " de "]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="499"
						y="4"
						width="36"
						height="12"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box>					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
					<textElement>
						<font fontName="Times New Roman" pdfFontName="Times-Roman" size="10"/>
					</textElement>
				<textFieldExpression   class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression>
				</textField>
				<line direction="TopDown">
					<reportElement
						x="0"
						y="3"
						width="535"
						height="0"
						key="line"/>
					<graphicElement stretchType="NoStretch"/>
				</line>
				<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
					<reportElement
						x="3"
						y="4"
						width="88"
						height="12"
						forecolor="#000000"
						backcolor="#FFFFFF"
						key="textField"/>
					<box>					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
					<textElement>
						<font fontName="Times New Roman" pdfFontName="Times-Roman" size="10"/>
					</textElement>
				<textFieldExpression   class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
				</textField>
			</band>
		</pageFooter>
		<summary>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</summary>
</jasperReport>
rdmardegam

Cara, fiz alguns teste aqui rapidamente !!

Quando n passa informações para o subrelatorio, o mesmo n era apresentado !!

Verifique se a query passada ao subrelatorio, retorna algum informação.

Até

Criado 25 de maio de 2010
Ultima resposta 25 de mai. de 2010
Respostas 3
Participantes 2