nusa Posted November 26, 2006 Share Posted November 26, 2006 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 More sharing options...
nusa Posted November 26, 2006 Author Share Posted November 26, 2006 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 More sharing options...
jisidro Posted November 26, 2006 Share Posted November 26, 2006 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 More sharing options...
Teodor Danciu Posted December 12, 2006 Share Posted December 12, 2006 Hi, The printWhenExpression expects a Boolean value and your conditional operator returns a String.So what are you actually tryin to do? Thanks,Teodor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now