Spring Web MVC - Spring Web Flow Working With JasperReports
Step 8: views files
We will see each resource file used by views.properties
First inicio.jsp code
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<center>
<p>
This Simple tutorial show you how use <i>Spring Web MVC</i> and <i>Spring Web Flow</i>
working together with <i>JasperReports</i>.
</p>
<ul>
<li>Spring Web MVC - JasperReports
<a href="/springjasperreports/prereportsimplejasperreport.htm">start</a></li>
<li>Spring Web Flow - JasperReports
<a href="/springjasperreports/springwebflowjasperreports.htm?_flowId=springwebflowjasperreports-flow">
start</a>
</li>
</ul>
</center>
</body>
</html>
It only offers two links to start each type of example process, as illustrated here:

If we do click in the first link, it must show the reportSimpleJasperReport.jsp. Below is the code
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>Spring Web MVC - JasperReports</title>
</head>
<body>
<center>
<br><br>
<p>
Click in <i>Generate Pdf</i> button to open a Pdf Report
</p>
<form action="/springjasperreports/reportsimplepdfjasperreport.htm" method="post" >
<input type="submit" class="button" name="next" value="Generate Pdf"/>
</form>
<p>
Click in <i>Go To Welcome Page</i> button if you want to start again
</p>
<form action="/springjasperreports/welcome.htm" method="post" >
<input type="submit" class="button" name="next" value="Go To Welcome Page"/>
</form>
</center>
</body>
</html>
It only consist in two forms, with an url action for each one, the purposes are obvious. Below the execution page
Note: I have configured my Web browser (Firefox/Opera) to open Adobe Reader to see the pdf report
Now if we do click in the second link in inicio.jsp, it must start the flow process, then the first view-state use swfjr-stepone.jsp, below the code
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>Spring Web Flow - JasperReports - Page One</title>
</head>
<body>
<center>
<p>
It is the first page of N pages of a flow process, it would be a simple form.
For simplicity it flow consist only in two pages.
</p>
<form action="" method="post" >
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionkey}"/>
<input type="submit" class="button" name="_eventId_next" value="Go To Page Two"/>
</form>
</center>
</body>
</html>
It consists of one submit button, below the jsp execution

If we do click in the button Go To Page Two we go to the next view-state and it use swfjr-steptwo.jsp, below the code
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>Spring Web Flow - JasperReports - Page Two</title>
</head>
<body>
<p align="justify">
It is the last page of N pages of a flow process.
For simplicity according to the explanation it gives the options to
<ul>
<li>Generate a pdf</li>
<li>Finish the flow process</li>
</ul>
In the case that you decide to finish the process without generate the pdf
and then after some time you want to see the report
(obvious that the flow process is already terminated),
then you should use Spring Web MVC for get the report like a simple search
</p>
<center>
<form action="" method="post" >
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionkey}"/>
<input type="submit" class="button" name="_eventId_next" value="Generate Pdf"/>
<br><br>
<input type="submit" class="button" name="_eventId_end" value="End Process"/>
</form>
</center>
</body>
</html>
The code is clear by itself, below is the jsp execution
Then the result desired is a pdf file, below the pdf generated
Here part of the SpringJasperReportsspring.jrxml, the "<field..." declarations
<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.*" />
<field name="idCustomer" class="java.lang.String"/>
<field name="nameCustomer" class="java.lang.String"/>
<field name="phoneCustomer" class="java.lang.String"/>
<field name="idProvider" class="java.lang.String"/>
<field name="phoneProvider" class="java.lang.String"/>
<field name="isbn" class="java.lang.String"/>
<field name="titleBook" class="java.lang.String"/>
<field name="priceBook" class="java.math.BigDecimal"/>
You would create your own war file and compile your SpringJasperReportsspring.jrxml with Ant tasks. (In a few days I will attach the source code to share)
I hope that this tutorial help you, if you have some doubt or recommendation, please let me know and sorry about my grammar.
In another Article, i will share perhaps the most important tutorial; the cumbersome case about Spring/JasperReports integration but related with Sub-Reports.
- Login or register to post comments
- 29765 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
clermont38 replied on Fri, 2009/05/15 - 12:18pm
cnbaluramesh replied on Sat, 2009/06/13 - 4:03am
vijayasaradhi_p replied on Tue, 2009/08/18 - 10:56pm
rajesh_dzone replied on Sun, 2009/09/27 - 9:47pm
zizul replied on Fri, 2009/11/13 - 5:24am
Manuel Jordan replied on Sat, 2009/11/14 - 10:23pm
Hello Guys
The source is almost available.
My hard disk crushed months ago, and the source code is somewhere among many DVD,
Regards