views:

44

answers:

3

Hey guys, 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 seems to work.

+1  A: 

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">
krock
it does not work because my total field(which is a concatenation of more than one individual field) is not null only a part of field which is null, which I want to avoid
Sachin Anand
A: 

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}
Vash
A: 

@Vash, Yes that is what I would do except I think you might want to put each expression inside of parenthesis's so that each expression is independent of the others. Like this:

($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})
rogiller
I've been doing this for a long time but I hope someone has a less verbose solution.
Alexander Ljungberg