English 中文(简体)
Field Expression in iReport
原标题:

I m trying to get myself used to iReport before using it in a real project next week and i seem to be stacked somewhere already. I m using iReport 3.7.0 on Windows XP platform + Java 1.6

It sound easy to get a field color changed based on what it contains or calculate a sum of number in a field based on conditions but in practice it s taking me too much time to accomplish. I have a query say :

SELECT COUNT(gender) AS total_by_gender, gender, account_status FROM user_account ua, user_profile up WHERE ua.user_profile_id=up.user_profile_id GROUP BY gender,account_status

it gives me something like this:

    | total_by_gender | gender | account_status |  
    | 160             |Female  | ENABLED        |  
    | 26              |Female  | UNCONFERIMED   |  
    | 100             |Male    | ENABLED        |
    | 10              |Male    | UNCONFIRMED    |    

Now I want the ENABLED Text to Look say green and UNCONFIRMED say `red. For that I added a text field with this expression

$F{account_status}.equals( new String("ENABLED") ) ? "<style forecolor= #ff0000 >" + $F{account_status}.toString() + "</style>" :"<style forecolor= #999999 >" + $F{account_status}.toString() + "</style>"    
//i ve tried this too
$F{account_status}.contentEquals( new String("ENABLED") )  ? 
//and even  
($F{account_status}.toString =="ENABLED"  ) ?

well for each of them it gives me something like the same text like <style> (i think it s printing all the condition expression) instead of colored text unconfirmed or enabled.

My second problem is that i want to do the total of all unconfirmed and all enabled. i can do normal sum expression but with condition i don t have any idea. Can anyone shed some light? thanks for reading

最佳回答

Try this. Define a style as below.

     <style name="myStyle" isDefault="false" mode="Transparent">
          <conditionalStyle>
              <conditionExpression><![CDATA[ YOUR CONDITION ]]></conditionExpression>
              <style isDefault="false" style="myStyle" backcolor="#E6DAC3"/>
          </conditionalStyle>
     </style>

And use it in your textFieldExpression

     <reportElement style="myStyle" x="1" y="0" width="100" height="15"/>
问题回答

Two issues here. 1. Your condition statement doesn t work. Try $F{account_status}.equals("ENABLED"). It will work. 2. You want to colour the text based on some condition. Check if iReport supports conditional colouring on textfield. If it does, try not to pollute the content with colour information (). Colour information has to be on the textfield and not the content of textfield. Please give complete textfield definition that you are using.

I ll try this myself tomorrow.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签