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条回答
再贱就再见
2楼-- · 2019-02-04 08:11

if you can use jasperreports-functions and you want to output String value, you can do it with function T() which returns text String or empty String.

T($F{firstName})

查看更多
一夜七次
3楼-- · 2019-02-04 08:11
($F{address_street1}.equals(null) ? "" : $F{address_street1}+ " ") + 
($F{address_street2}.equals(null)l ? "" : $F{address_street2}+ " ") +
($F{address_state}.equals(null) ? "" : $F{address_state}  + " ") +            
($F{address_country}.equals(null) ? "" : $F{address_country}+ " ") +           
($F{address_zip} .equals(null) ? "" : $F{address_zip})
查看更多
登录 后发表回答