Jump to content
JasperReports Library 7.0 is now available ×

Using constant in printwhenexpression


nusa

Recommended Posts

Hi,

 

I have a problem using the following expression :

Code:
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : "Good morning : " + $F{name} ]]></printWhenExpression>
/[code]

Basically, I just want to print a blank or "Good morning : " + $F{name}. The above expression gave me a class cast exception.

Any help would be appreciated.

Thanks. 
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

nusa wrote:

Hi,

I have a problem using the following expression :
Code:

<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : "Good morning : " + $F{name} ]]></printWhenExpression>
/
Code:
[code]

Basically, I just want to print a blank or "Good morning : " + $F{name}. The above expression gave me a class cast exception.

Any help would be appreciated.

Thanks.

 

Sorry, error in formating the code, it should be :

Code:
[code]
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : "Good morning : " + $F{name} ]]></printWhenExpression>

 

Any help how to fix the above code ?

 

The other thing is, how can I print a set of fields based on a condition of a field ?

Say, if I want to print each address, city, country, phone nb, email, etc ( not concatenation of those ), if $F{name} is not emptry or null ?

Do I need to do :

Code:
[code]
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : $F{address} ]]></printWhenExpression>
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : $F{city} ]]></printWhenExpression>
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : $F{country} ]]></printWhenExpression>
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : $F{phone nb} ]]></printWhenExpression>
<printWhenExpression><![CDATA[$F{name}.equals( "" ) ? null : $F{email} ]]></printWhenExpression>

Is there any other way ?

 

Thanks for any help/suggestion.

Link to comment
Share on other sites

Hi!

 

I think you have the class cast exception because the operation equals() needs an Object and you pass a String.

 

You can try it:

 

Code:
<printWhenExpression><![CDATA[$F{name}.equals( (Object) new String(""«») ) ? null : "Good morning : " + $F{name} ]]></printWhenExpression>

 

If $F{name} is a String you can use the funciton compareTo.

 

Code:
[code]<printWhenExpression><![CDATA[$F{name}.compareTo( "" )==0 ? null : "Good morning : " + $F{name} ]]></printWhenExpression>

 

I hope this helps you!

 

Jordi

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...