Sunday, September 25, 2005

JHeadstart with Jasper Reports

I am currently developing an application using JHeadstart and JasperReports. I am able to leverage the powers of JHS to generate the parameter forms for me. Using JHS makes it conventient as drop downs, LOV, etc can all be used in the parameter forms. Following hopefully will help anyone who is trying to do the same.

Writing the Reports

We used iReport to create the reports. This tool provides a nice GUI for generating the report files. When creating parameters for your reports, you should use the same naming convention as used by Oracle ADF. As an example, if you have a database column with the name of EMPLOYEE_NAME, ADF would generate the name EmployeeName. Thus, you should name your paramers in Jasper the same way. This will make the ADF components you developed consistent and making passing the parameters to Jasper considerably easier. When you create parameters in Jasper, you need to specify the datatypes. I went ahead and declared all of my dates as String and then in the SQL query I convert them back to a date. This will ensure that you use any indexes that might exist on date fields. As an example:

AND BEGIN_DATE = TO_DATE(${BeginDate}, 'mm-dd-yyyy')

Passing Parameters to Jasper

When running a Jasper Report that requires parameters, Jasper requires the parameters to be placed into a HashMap. I wanted to create a general method for putting the required parameters into the required HashMap format. Knowing that I was going to use View Objects (VO) for the fields on parameter forms, I went ahead and created a generic VO (GeneralReportView) that all parameter form VOs would extend. I added custom code in the VO to rip through all of the attributes and put them into a HashMap thus allowing me to pass them to Jasper. I only need to add one method. Following is the method I added:


Creating View Objects

For each parameter form I am using a VO for all of the necessary parameters. When creating the VO, I am selectings "Rows Populated Programmatically..." and specifying the VO extends my base VO I describe above (GeneralReportView). When creating the attributes, make sure you use the same naming convention as you did when creating the reports. Also, make sure you are using the correct data types. Making sure your names and data type are correct will ensure that when passing them to Jasper as a HashMap they will be resolved correctly and the report will be able to run. The only option I have specified for an attirbute is "Updateable=Always". None of the other options are checked.

Application Flow

When creating an application you must have a flow. JHS will generate a flow, as long as it is data driven such as through parent-child relationships. I knew when running reports, the user would be taking three steps most of time. These steps are:

1) Select the report
2) Enter parameters
3) View Report

For the most part, when JHS generates a page and you are executing an action on that page, after the action completes you are taken back to the same page. You are not "navigated" to the next one. I had questioned if JHS was going to help but then this blog came to the rescue. What that blog showed me was that using custom templates you could control this. So, I went ahead and modified these same templates to use this wizard type interface. I now use these mofified tempates to generate a page to select the report, enter the parameters, and then finally view the generated report.

There is still some logic that has to be built into the three steps above. Such as, after step 1 the decision needs to be made "what parameter form should be displayed?". Then, after step 2 the decision needs to be made "what report should be generated?". I simply created struts actions to handle my application flow.

Gererate the Paramater Forms

For each unique parameter form, you will need to create a different ViewObject using the steps described above. If you have reports that use the same parameters, you can use the same VO, you just need to generate seperate pages. When creating the VOs, make sure to extend the base VO (GeneralReportView) and then add to your application module so that JHS can see it. In JHS Application Struture file, create a new Base Group based on your VO and using any necessary templates you will be using. Run the application generator and your parameters forms will be created.

Screenshots


Report Manager - User may view the reports they have executed previously or
select "Run Report" to run a new one.



Select Report - User selects the report they want to run.



Enter Parameters - User enters the desired parameters for the report.



View Report - User can see the report that she ran and click on the link
to open it.


I don't have the user interface 100% complete but the functionality is there. Using JHS & Jasper has made it very easy to intergrate reports into our application.

Thursday, September 22, 2005

Securing JHeadStart Applications

Securing JHeadStart can be a tricky subject but following a few recent posts you can get this up and running smoothly. In order to get the best security services, you'll want to utilize declaritive J2EE using JAAS. This post will be covering using JDev 10.1.2 and OC4J 10.1.2.

First, you'll need to follow How To Add J2EE Authentication and Authorization to JHeadstart Applications. That will get you setup using the jazn-data.xml for the user's credentials. This works well, but more than likely if you are not using some type of LDAP server for security you are probably acquiring your credentials from a database table (like me). But, you will need to follow these steps to setup security so that it is enabled while you are working with your application in JDeveloper. You want your development environment to as close to the production enviornment as possible .

Once you have that configured, you'll be ready to deploy your app to OC4J. I'm using creditials authorized from a database table as oppposed to the jazn-data.xml file as the user's creditials are always being added, deleted and modified. In order to get this setup, you will want to read Declartive J2EE authentication and authorization with JAAS. It took me several times to get my app running using the login module as described in this paper. I highly recommend making sure you can get the example code working first and understand it before applying to your JHeadStart application.

Before I deploy my application to OC4J, there is one change I am having to make to my web.xml file. Open properties for web.xml and remove Realm from Login Configuration. I remove the text, deploy to OC4J, and then put the line back in there so that it runs in JDev.