Jump to content
We've recently updated our Privacy Statement, available here ×

doubt in Print whenExpression


rasikow

Recommended Posts

 Hi all,

I am fetching data from database.

when field comes as "1", i want to display as "India"

when field comes as "2", i want to display as "USA"

when field comes as "3", i want to display as "Japan"

when field comes as "4", i want to display as "China"

...etc.

How to do this in jrxml file? your swift reply shall be highly appreciated.

Thanks in advance.

 

- Gnaniyar Zubair

 

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

There are two easy ways:

 * Change your query to do this, assuming you don't have table with country codes to join on to you could use a database specific query, e.g. in oracle use a decode ala

      DECODE(field, 1, 'India', 2, 'USA', 3, ...)

* Or a more portable way try using an expression like

      $F{f}.intValue() == 1 ? "India" :  $F{f}.intValue() == 2 ? "USA" : $F{f}.intValue() == 3 ? "Japan" : "China"

If the above is something you need to do often I'd create a utilty method in java and add it to the class path.

Personally, if it was possible, I'd create a table for enumerated values and change the query to a join to pull in the country name, e.g.

SELECT p.name, c country_name FROM person p, country c WHERE p.country_id = c.country_id

Regards, Vic

Link to comment
Share on other sites

 Hi all,

 

how can i give 2 conditions in printwhenexpression?

For example, if value is 1, that field should print, for that i have written this coding in printwhenexpression:

$F{value} = 1

But i want to check 2 conditions like if value is equal to 1 and  2, For that can i write like this?

$F{value} = 1 ||  $F{value} = 2  

( But i got the error that i cant use this OR symbol || in jrxml).. Then How to write?

Thanks in advance

 

- Gnaniyar Zubair

 

 

Link to comment
Share on other sites

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...