How to avoid null values in jasper reports

2019-02-04 07:28发布

I have a field in my jasper report which has a expression value like

$F{address_street1}+" "+$F{address_street2}+ " " +$F{address_state} + " "+$F{address_country}+ " "+$F{address_zip}

My problem is that if any of the fields in here is null I get the null value between other things like

101 Main St****null****ILUnited States12345 

Notice the highlighted null. Is there any way I can avoid that?

I have tried checking the null value for a particular field in it using boolean expression and replacing it with blank, but that doesn't seem to work.

14条回答
SAY GOODBYE
2楼-- · 2019-02-04 07:56

You can write a java Code

 package com.xyz

 Class ReportUtil 
  {
      public static String getMyString (String str1 , String str2)
         {
             if((str1!=null) && (str2!=null))
                 return str1 + " " + str2 ;
             else if str1==null
                  return str2 ; 
             return str1 ;                            
          }

   }

In JRXML , you can use the following expression in the textbox

com.xyx.ReportUtil.getMyString ($F{firstName},$F{lastName}) 

Set "Is blank When null" property to true

Regards,

Ankush

查看更多
我想做一个坏孩纸
3楼-- · 2019-02-04 07:58

Set the property isBlankWhenNull to true.

  • In iReport check the Blank When Null checkbox when your field is selected.
  • In jasper jrxml file: <textField isBlankWhenNull="true">
查看更多
何必那么认真
4楼-- · 2019-02-04 07:58

I have the option (Blank when Null) checked for every field in the report and still seeing nulls on the fields. So, I used report expressions.

Since every report variable is a string, to check for null use:

$F{address_stree2}.equals("null") 
查看更多
冷血范
5楼-- · 2019-02-04 08:03

You can set the textfield height as 1, set the Stretch with overflow flag as true and Blank when null as true so when field value is blank it will not leave blank space between.

查看更多
够拽才男人
6楼-- · 2019-02-04 08:08

In The Expression You are allowed to use the Java code.

So what You need to do is to check that the value of field is null if is then replace it with empty string.

$F{address_street1} == null ? "" : $F{address_street1}+ " " +
$F{address_street2} == null ? "" : $F{address_street2}+ " " +
$F{address_state} == null ? "" : $F{address_state}  + " " +
$F{address_country} == null ? "" : $F{address_country}+ " " +
$F{address_zip} == null ? "" : $F{address_zip}
查看更多
小情绪 Triste *
7楼-- · 2019-02-04 08:10

If you are working in ecliple+jasper softReports you just fallow below steps 1.select field + rightclick and select showProperties option 2.click TextField select BlankWhenNull 3.Compile and Rebuild check it.

查看更多
登录 后发表回答