Warriors vs Spurs highlights up
To help everyone forget about tonight’s debacle in Portland, check out my highlights from the Spurs game on Monday.
Winning the Web contest
I saw this contest on Winning the Web where I have a chance to win $100 and a free t-shirt. All I have to do is write a post about who should win the contest, Winning the Web or TylerCruz.com. The loser of the contest will pay $100 to 3 lucky contest participants who voted for the winning blog. So I’m dusting off this blog and I’ve decided to vote for…drumroll please… Gyutae Park’s Winning the Web!
Ok, here three reasons why I’m voting for him:
1) Gyutae figured out a great way to get his blog out there by promoting a contest on JohnChow.com. Because of it, I checked out his blog and I found that he had a lot of great content about making money on the web. He has a lot of creative ideas (as evidenced by this contest) and he knows how to write. Winning the Web is now one of my regular reads on my RSS reader.
2) The guy is rich! He spent $1500 on a contest to promote his blog by buying two Johnchow reviews and a Johncow review. I wish I was rich…
3) I need a new shirt to wear. Although honestly, the shirt looks kind of ugly and purple. But with $100 I could buy a better, nicer, non-purple shirt, and I could use this shirt to clean my toilet.
Honestly, I’m impressed by how creative both these two bloggers are with this contest. I hadn’t heard about TylerCruz.com before but I just checked it out and it looks like a good read as well. So now I’m going to add the blog to my RSS feed as well. And who knows? Maybe for their next contest, I will vote for Tyler. Unless I win the $100. In that case, it’s Winning the Web forever! Alright, I just needed to write 300 words so that about does it.
Learning JasperReports
At work, I've been tasked to do some reporting for a Java application that we have and I've been trying to learn the JasperReports library. Unfortunately, the existing documentation/tutorials that I've found have been somewhat limited. For example, I spent a few days pulling my hair out trying to understand how to get the subreports functionality working. I think I've figured out the basics now, so here is a simple tutorial.
Setup
- Download JasperReports 1.2.7
- Download IReport Designer 1.2.7
- I'm using Eclipse as my Java development environment, but you can use whatever you want.
Creating our project
In Eclipse, create a new Java project. To get everything compiled correctly, you need to have the following jars (from the JasperReports distribution) in your project classpath.
- jasperreports-1.2.7.jar
- commons-digester-1.7.jar
- commons-collections-2.1.jar
- commons-logging-1.0.2.jar
- commons-beanutils-1.5.jar
- itext-1.3.1.jar
Also, create a reports subdirectory for my reports to go into. For this simple project, I want to display in a subreport a list of PersonBean objects.
iReport is a visual reporting tool for creating JasperReports which frees you from having to muck with the JasperReports jrxml files. It's free and so far seems pretty decent.
Open it up, and go to the File menu > New Document. I created a document called 'master' which will generate a master.jrxml file for you. Use the 'Static Tool' button in the toolbar to add some text to the detail band.
To embed a subreport, Go to Edit menu > Insert Element > Subreport and then clicked on a spot in the detail band. This will bring up the Subreport wizard. Choose to create new subreport and accept all the defaults.
Back in the IDE, you need to write some code to compile the jrxml files.
JasperReport jasperReport = JasperCompileManager.compileReport(
"reports/master.jrxml");
// compile subreport
JasperReport subReport = JasperCompileManager.compileReport(
"reports/subreport.jrxml");
There are two parameters to pass in, the subreport and a datasource. In this example we are using a net.sf.jasperreports.engine.data.JRBeanArrayDataSource object which accepts an array of JavaBean objects.
parameters.put("subreport", subReport);
PersonBean[] people = new PersonBean[] {
new PersonBean("Bob", 21, "New York"),
new PersonBean("Chris", 27, "California"),
new PersonBean("Sally", 30, "Texas")
};
JRBeanArrayDataSource ds = new JRBeanArrayDataSource(people);
parameters.put("subreportData", ds);
After that we fill the report and output the file to pdf.
parameters, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint,
"reports/myreport.pdf");
Now we go back to iReport and finish up our reports. In our subreport, add a columnHeader band, and then add the three column titles (name, age, location) to it. In the detail band, add the corresponding three fields ($F{name}, $F{age} and $F{location}. Make sure you set the age field expression class to java.lang.Integer and declare fields (View > Fields). You should have something similar to this:

Switch to the master report, right click on the subreport image and select 'Properties'. In the Subreport tab, choose 'Use datasource expression' in the combo and input '$P{subreportData}' as your expression. Switch to the Subreport (other) tab, select 'net.sf.jasperreports.engine.JasperReport' and input '$P{subreport}' as your expression. These correspond to the two parameters we passed in above in the Java code. Finally declare the two parameters (View > Parameters).
To actually generate the report, go back to your IDE and run the java code. A sparkly new pdf awaits.
Author Name
A couple of lines for short desc
ription of the author of this
blog A couple of lines for short
description of the author of
this blog description of the
author of this blog
description of the author
