Précédent   Forum des professionnels en informatique > Logiciels > Solutions d'entreprise > Business Intelligence > Jasper
Jasper Forum d'entraide sur Jasper Reports. Avant de poster --> FAQ Jasper, Tutoriels Jasper
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 17/03/2008, 13h50   #1
Membre confirmé
 
Développeur informatique
Inscription : mars 2008
Messages : 155
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : mars 2008
Messages : 155
Points : 280
Points : 280
Par défaut [JAVA] Afficher rapport directement à l'écran

Bonjour!

J'ai déjà réussi à exporter un Jasper report vers un fichier PDF via une classe JAVA.
Maintenant, j'aimerais pouvoir afficher ce rapport directement à l'écran, toujours avec une classe JAVA. N'existerait-il pas quelque chose comme un "viewer"?

Quelqu'un peut-il m'aider?

D'avance merci!
AnneCa est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/03/2008, 09h15   #2
Membre éclairé
 
Inscription : avril 2007
Messages : 195
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 195
Points : 320
Points : 320
Bonjour,

Tu peux utiliser la classe net.sf.jasperreports.view.JRViewer pour ce faire.
Il s'agit d'une classe dérivant de javax.swing.JPanel qui permet d'afficher des rapports générés (sous forme d'objets en mémoire, de fichiers sur le disque ou encore de fluxs XML).
__________________
Cordialement,

*****************
Christopher André
Sales Engineer

Voir mon profil

Il est extrêmement rare que je réponde à un message privé.
Contribuez à la FAQ Jasper Reports & iReport
candre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2008, 10h54   #3
Membre confirmé
 
Développeur informatique
Inscription : mars 2008
Messages : 155
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : mars 2008
Messages : 155
Points : 280
Points : 280
OK, je vais voir ce que je peux faire et je te dis quoi dès que possible
AnneCa est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/04/2008, 12h09   #4
Membre confirmé
 
Développeur informatique
Inscription : mars 2008
Messages : 155
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : mars 2008
Messages : 155
Points : 280
Points : 280
Après quelques petites recherches additionnelles avec Google, je puis vous faire part de mes trouvailles (et elles marchent).

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
import java.awt.BorderLayout;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
 
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JRViewer;
 
public class JasperViewer extends javax.swing.JFrame {
 
	private JRViewer viewer = null;
	private boolean isExitOnClose = true;
 
	/** Creates new form JasperViewer */
	public JasperViewer(JasperPrint jasperPrint) {
		this.isExitOnClose = true;
 
		initComponents();
 
		this.viewer = new JRViewer(jasperPrint);
		this.pnlMain.add(this.viewer, BorderLayout.CENTER);
	}
 
	/** Creates new form JasperViewer */
	public JasperViewer(JasperPrint jasperPrint, boolean isExitOnClose) {
		this.isExitOnClose = isExitOnClose;
 
		initComponents();
 
		this.viewer = new JRViewer(jasperPrint);
		this.pnlMain.add(this.viewer, BorderLayout.CENTER);
	}
 
	/** This method is called from within the constructor to
	* initialize the form.
	* WARNING: Do NOT modify this code. The content of this method is
	* always regenerated by the Form Editor.
	*/
	private void initComponents() { //GEN-BEGIN:initComponents
		pnlMain = new javax.swing.JPanel();
 
		setTitle("JasperViewer");
		setIconImage(
			new javax
				.swing
				.ImageIcon(
					getClass().getResource(
						"/net/sf/jasperreports/view/images/jricon.GIF"))
				.getImage());
		addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent evt) {
				exitForm();
			}
		});
 
		pnlMain.setLayout(new java.awt.BorderLayout());
 
		getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);
		pack();
		java.awt.Dimension screenSize =
			java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		setSize(new java.awt.Dimension(750, 550));
		setLocation(
			(screenSize.width - 750) / 2,
			(screenSize.height - 550) / 2);
	} //GEN-END:initComponents
 
	/** Exit the Application */
	void exitForm() { //GEN-FIRST:event_exitForm 
		if (this.isExitOnClose) {
			System.exit(0);
		} else {
			this.setVisible(false);
			this.viewer.clear();
			this.viewer = null;
			this.getContentPane().removeAll();
			this.dispose();
		}
 
	} //GEN-LAST:event_exitForm
 
	/**
	* @param args the command line arguments
	*/
	public static void main(String args[]) {
		String fileName = null;
 
		 String url = "jdbc:as400://maMachine";
		 String login = "xxxxx";
		 String password = "yyyyy";
		 Connection connection = null;
 
		try {
			 // - Connection to DB
			 Driver myDriver = new com.ibm.as400.access.AS400JDBCDriver();
			 DriverManager.registerDriver(myDriver);
			 connection = DriverManager.getConnection(url, login, password);
			 System.out.println("Connection is OK");
 
			 // - Load & compile report
			 JasperDesign jasperDesign = new  JasperDesign();
			 jasperDesign = JRXmlLoader.load("C:\\Program Files\\JasperSoft\\iReport-2.0.4\\jrxml\\TEST1.jrxml");
 
			 System.out.println("Load is successful");
			 JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
			 System.out.println("Compile is OK");
 
			 // - Paramètres à envoyer au rapport
			 Map parameters = new HashMap();
			 parameters.put("Titre", "All customers");
			 System.out.println("Put param is OK");
 
			 // - Execution du rapport
			 JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection);
			 System.out.println("Fill report is OK");
			 // - Création du rapport au format PDF
			viewReport(jasperPrint);
 
			} catch (JRException e) {
					 System.out.println("JRException");
					 e.printStackTrace();
			} catch (SQLException e) {
					 System.out.println("SQLException");
					 e.printStackTrace();
			} finally {
					 try {
						  connection.close();
						 //System.out.println("Connection is closed");
						 } catch (SQLException e) {
						 System.out.println("SQLException: close connection");
								 e.printStackTrace();
						 }
		}
	}
 
	/**
	*
	*/
	private static void usage() {
		System.out.println("JasperViewer usage:");
		System.out.println("\tjava JasperViewer -XML -Ffile");
	}
 
 
	/**
	*
	*/
	public static void viewReport(JasperPrint jasperPrint) {
		JasperViewer jasperViewer = new JasperViewer(jasperPrint, true);
		jasperViewer.setVisible(true);
	}
 
 
	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JPanel pnlMain;
	// End of variables declaration//GEN-END:variables
 
}

Encore merci à candre.
AnneCa est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/04/2008, 14h59   #5
Membre éclairé
 
Inscription : avril 2007
Messages : 195
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 195
Points : 320
Points : 320
Content de voir que tu as pu obtenir ce que tu cherchais.
Peux-tu le poster sur la FAQ, s'il te plait?
Merci d'avance.
__________________
Cordialement,

*****************
Christopher André
Sales Engineer

Voir mon profil

Il est extrêmement rare que je réponde à un message privé.
Contribuez à la FAQ Jasper Reports & iReport
candre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/04/2008, 16h45   #6
Membre confirmé
 
Développeur informatique
Inscription : mars 2008
Messages : 155
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : mars 2008
Messages : 155
Points : 280
Points : 280
Voilà! Je viens d'ajouter un FAQ. Belle journée!!
AnneCa est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h02.


 
 
 
 
Partenaires

Hébergement Web