13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>With JasperReports 3.1, the JRXML syntax moved from a DTD-based definition to XML-based schema. The XML sourcedeclaration syntax now references a schema file, rather than a DTD. Based on what we said previously, this is not a problemsince UR assures backwards compatibility. However, many people have been used to designing reports with earlyversions of <strong>iReport</strong> then generating the reports by compiling JRXML in UR. This was always a risky operation, butit was still valid because the user was not using a new tag in the XML. With the move to an XML schema, the JRXML outputof <strong>iReport</strong> 3.1.1 and newer can only be compiled with a JasperReports 3.1.0 or later.3.5 ExpressionsThough I designed <strong>iReport</strong> to be useful for non-technical report designers, many settings in a report are defined using formulas(such as conditions to hide an element, special calculations, text processing, and so on) that require a minimum knowledge ofa scripting language.Fortunately, formulas can be written in at least three languages, two of which (JavaScript and Groovy) are pretty simple andcan be used without knowledge of programming methods.All of the formulas in UR are defined through expressions. The default expression language is Java, but I suggestthat you design your projects with JavaScript or Groovy. Both hide a lot of the Java complexity and are definitively thelanguages to use if you don’t know Java. The language is a property of the document, so, to set it, select the document rootnode in the Outline view and choose your language in the Language property in the Properties view. We will go through allthe languages in the following sections, but let’s concentrate for a moment on our definition of an “expression,” in particularthe type you will declare for it and why that is important in UR.An expression is just a formula that operates on some values and returns a result. Think of an expression as the formula youmight define for a spreadsheet cell. A cell can have a simple value or you can use a complex formula that refers to othervalues; in a spreadsheet you would refer to values contained in other cells, whereas in UR you will use the reportfields, parameters, and variables. The main point is that whatever you have in your expression, when it is computed it gives avalue as result (which can be null; that’s still a value).3.5.1 The Type of an ExpressionThe type of an expression is the nature of the value resulting from it; the type is determined by the context in which theexpression is used. For example, if your expression is used to evaluate a condition, the type of the expression should beBoolean (true or false); if you are creating an expression that should be displayed in a textfield, it will probably be a String ora number (Integer or Double). We could simplify the declaration of types by limiting them to text, numbers, Booleans, andgeneric object values. Unfortunately, UR is a bit more formal and in many cases you have to be very precise whensetting the type of your expression.So far, we are discussing only Java types (regardless of the language used). Some of the most important types are:java.lang.Booleanjava.lang.Bytejava.lang.Shortjava.lang.Integerjava.lang.Longjava.lang.Floatjava.lang.Doublejava.lang.StringDefines an Object that represents a boolean value such as true andfalseDefines an Object that represents a byteDefines an Object that represents an short integerDefines an Object that represents integer numbersDefines an Object that represents long integer numbersDefines an Object that represents floating point numbersDefines an Object that represents real numbersDefines an Object that represents a text38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!