Olá, estou a quase dois dias quebrando a cabeça mas desisto.
Estou com problema ao passar parâmetros para o Relatório no Ireport, consegui mostrar o relatorio na tela normal , so que o parâmetro não está indo, nao sei onde estou errando.
A CLASSE DE GERAR RELATORIOS:
package com.winsae.Conexoes;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@SuppressWarnings("serial")
public class RelatorioPessoa extends HttpServlet{
//caminho dos arquivos do java e flex
private static String javaPath;
private static String flexPath;
private String loja;
/** AQUI CONFIGURO O PARAMETRO QUE VEM DO FLEX */
public void setLoja(String loja)
{
this.loja = loja = " ";
}
public RelatorioPessoa()
{
}
@SuppressWarnings("static-access")
public void service(HttpServletRequest request, HttpServletResponse response)
{
if(this.javaPath == null && this.flexPath == null){
this.javaPath = this.getServletContext().getRealPath("WEB-INF/classes/");
this.flexPath = this.getServletContext().getRealPath("/assets");
}
String Relatorio = request.getParameter("relatorio");
if(Relatorio.equals("ResumoDiario"))
{
try
{
//chama o programa de gerar o relatorio
geraResumoDiario(request, response);
}catch(JRException erro){
erro.printStackTrace();
}
}
else if(Relatorio.equals("Pessoa1"))
{
try
{
//chama o programa de gerar o relatorio
geraRelatorioPessoas(request, response);
}catch(JRException erro){
erro.printStackTrace();
}
}
}
//TODO criado para mostrar o resumo diario passando os paramentros data inicial, data final e loja
@SuppressWarnings("unchecked")
public void geraResumoDiario(HttpServletRequest request, HttpServletResponse response) throws JRException
{
//mostrando o caminho do relatorio
String caminhoRelatorio = javaPath+"/com/winsae/Relatorios/RelatorioTeste.jasper";
//preenchendo os parametros do relatorio
HashMap parametros = new HashMap();
// parametros.put("DATA_INICIAL", stringFlexData("01/12/2009"));
// parametros.put("DATA_FINAL", stringFlexData("15/12/2009"));
//parametros.put("DATA_INICIAL", "01.12.2009");
// parametros.put("DATA_FINAL", "15.12.2009");
parametros.put("LOJA", loja);
//chamando a conexao
ConnectionFactory con = new ConnectionFactory();
byte [] pdfResumoDiario = JasperRunManager.runReportToPdf(caminhoRelatorio, parametros, con.getConnection());
mostarRelatorioPdf(pdfResumoDiario, response);
}
@SuppressWarnings("unchecked")
public void mostarRelatorioPdf(byte [] relatorio, HttpServletResponse response)
{
try
{
ServletOutputStream out = response.getOutputStream();
response.setContentType("application/pdf");
out.write(relatorio);
}catch(IOException e){
e.printStackTrace();
}
}
}
E esse é o meu codigo Flex;
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:local="*"
xmlns:flexlib="http://code.google.com/p/flexlib/"
width="344" height="144" close="close()" title="Resumo Diario">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="relatorio" destination="relatorio" fault="OnFault(event)">
<s:method name="setLoja"/>
</s:RemoteObject>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.Fault;
import flexlib.mdi.containers.MDICanvas;
import flexlib.mdi.containers.MDIWindow;
public function OnFault(event:FaultEvent):void
{
Alert.show(event.message.toString());
}
public function passaParametros():void
{
relatorio.setLoja(loja.text);
}
public function close():void
{
PopUpManager.removePopUp(this);
}
public function showForm(window:MDIWindow):MDIWindow{
var finalWindow:MDIWindow = null;
var windowExists:Boolean = false;
var main:TTT = new TTT();
for (var i:String in main.MDI.getChildren()){
var objMDI:MDIWindow =
MDIWindow(main.MDI.getChildAt(int(i)));
if (window.className == objMDI.className){
window = null;
finalWindow = objMDI as MDIWindow;
windowExists = true;
break;
}
}
if (windowExists){
if (finalWindow.minimized){
finalWindow.maximized;
finalWindow.showControls = true;
}else{
main.MDI.windowManager.bringToFront(finalWindow);
}
}else{
finalWindow = window;
main.MDI.windowManager.add(finalWindow);
}
return finalWindow;
}
]]>
</fx:Script>
<s:controlBarContent>
<s:Button label="Visualiza" fontSize="14">
<s:click>
<![CDATA[
public var TWMostraRelatorio:MostraRelatorio = new MostraRelatorio();
passaParametros();
TWMostraRelatorio.setUrl("resumoDiario?relatorio=ResumoDiario");
PopUpManager.addPopUp(TWMostraRelatorio, this, true);
// PopUpManager.centerPopUp(TWMostraRelatorio);
]]>
</s:click>
</s:Button>
<s:Button label="Cancelar" fontSize="14"/>
</s:controlBarContent>
<s:Label x="10" y="10" fontSize="14" text="Data Inicial:"/>
<mx:DateField x="10" y="32" width="131"/>
<s:Label x="149" y="10" fontSize="14" text="Data Final:"/>
<mx:DateField x="149" y="32" width="131"/>
<s:TextInput x="288" y="32" width="40"/>
<s:Label x="288" y="10" fontSize="14" text="Loja:" id="loja"/>
<!--
<flexlib:MDICanvas id="mdiCanvas" x="11" y="57" width="863" height="392">
</flexlib:MDICanvas>
-->
</s:TitleWindow>
Obrigado a todos.