15. Februar 2009

Using JasperReports in your Flex Application

Filed under: Flex,Technologie — Patrick | 20:42 Digg It!

Last week, I came cross the Flash Viewer for JasperReports. JasperReports is an OpenSource Java Framework to build Reports based on different data sources. We’re using in our projects JasperReports to generate PDF reports, too.

The Flash Viewer Project is using the Flex SDK to render the JasperReports for the HTML or Web based application. All source files of the viewer are available, so that you can customize the viewer for your needs.

But you can’t replace a interactive Flex chart component with the report viewer, because the viewer only generates a static output of the report. You can also using the JFree Chart extensions of the JasperReports, but neither the Charts nor the Text Information are selectable. If you’re changing any data of the report, you have to fill the report again in your Java Backend and rerender the report with the viewer.

So, using the viewer make only sense if you using it as preview of the report or if your reports aren’t as complex and interactive. And the best thing about the viewer is that you can use the same source file for your web and print output.

Additional Infos:

To use the Flash Viewer, you have to setup a Java web server like (Tomcat…) and run the webapp of the Flash Viewer. You get the webapp, if you download the project zip of the Flash Viewer. To display a report, you have to compile the report definition (jrpxml file) and fill the the compiled report. After that, you can use the Flash Viewer to display the report. The project zip contains a sample report, which demostrates how to use the flash viewer.

Flex Flex  Jasper Reports Jasper Reports 

3. Februar 2009

Number in Flex3 and the decimal separator

Filed under: Adobe,Flex — Patrick | 23:54 Digg It!

Today, I decided to write my first blog post in English. The reason for this post is the implementation of Number in current Flex3 SDK. I haven’t used Number as input for a while, the last time about one or one and half years ago. What had changed during this time: You can’t directly parse a String into Number if you using a comma as decimal separator.I used the resource bundle properties to change the decimal and thousand separator.

SharedResources.properties:

# CurrencyFormatter, NumberFormatter, Slider
decimalSeparatorFrom=.
decimalSeparatorTo=,
thousandsSeparatorFrom=,
thousandsSeparatorTo=.

validators.properties:

# Currency/Number Validator
allowNegative=true
decimalSeparator=,
maxValue=NaN
minValue=NaN
thousandsSeparator=.

If you trying parse the String into Number using current 3.2.0 Flex SDK, the result is always NaN. In Flex 2 this transformation worked perfect.

var s:String = “0,5″

var n:Number = Number(s);

=> n = NaN

Also the parseFloat function can’t parse the String into Number. The function cuts off the decimal value of the Number if you using a comma. The only way to do this transformation is using a regular expression to replace the comma with a point and than transform the String into a Number. If you have multiple input fields with numbers, this is no satisfying solution.

When I read some JIRAs at the Adobe Bug and Issue Management System, I found a couple of bugs which are related to this problem. The NumberValidator and CurrencyValidator doesn’t work correct if you using a comma as decimal separator. They can’t validate if the number is in the range of min and max values of the validator. Before comparing the input against the min and max values they transform the String into Number by using following code.

var x:Number = Number(input);

The result of this transformation using a comma as decimal separator is always NaN.  Line 295 of the NumberValidator and line 343 of the CurrencyValidator Adobe uses this transformation. So, the validation of min and max couldn’t work using a comma.

Please, Adobe correct the implemtation of Number.

Bug Bug  comma comma  CurrencyValidator CurrencyValidator  decimalseparator decimalseparator  Flex Flex  Number Number  NumberValidator NumberValidator  SDK SDK