Is there any way to set a default value to a field in a report? I have a lot of String fields in a report and would like them to display "0,00" when they're null.
标签:
jasper-reports
相关问题
- Jasper: error opening input stream from url
- JasperReports Server parameter dependency
- is it possible print element only when its detail
- JasperReports CompileReport
- Print an arraylist content with JasperReports
相关文章
- How to set up jasper reports in spring with subrep
- Modularization of Jasper reports: Pass data source
- How to use jasperreports subreports with grails ja
- Current URL /web/guest/HTML generates exception: n
- SAX2 driver class not found
- Passing array data from PHP to JasperReports (with
- How to force image url in jasper report export to
- SubReport not shown
Did you try set a pattern in the text field?
If you are using iReport this can be found in the properties for the text field in the
Text Field Properties
section.Try something along the lines of
###0.00
to represent 1234.56, which would always display 0.00 even if it is null.This is the easiest way is to use
Coalesce() or NVL()
function of database in your data-source query to restrict null data on your report.But it depends on if you are allowed to change the datasource query or not. If not then you can go for other solutions provided in previous answers.
medopal's answer is good, but 2 additions:
1) You can make the syntax shorter:
($F{field_name}) ? $F{field_name} : "0.00"
2) Make sure your "else" data is of the same class as the field's value, otherwise you'll get errors when it tries to coerce numbers into string, etc. etc. This was something that, as I started out, I mixed up.
Supposing the field name is "value", in the "Text Field Expression", write:
($F{value} != null) ? $F{value} : "0.00"
You can also select "Blank when null" in the properties of the text field if you want that. Other options are more flexible but this does the trick very quick and easy.