简体   繁体   中英

How to map key-values in JasperReports?

I'm translating a java object to JasperReports for PDF templating.

I want to map a string, and depending on its value value map to a text representation. Like:

one=this is one string
two=this is two string
three=this is three string
...

How can I add some kind of keyvalue map inside jasper reports, so that I can read the property from the java object and map it inside jasper?

JasperReport always receive a Map as Input Parameter. In such map you can put anything you want, even another map that meets your needs...

So, you have two ways to reach your goals:

One, is to build your own map and put it inside the map which jasper report take as input argument... Then, inside your jasper report, define a parameter of java.util.Map type and name it exactly as the key that maps your map inside the jasper report input parameters map (let's suppose that your map was called MY_MAP).

Later, when you need to retrieve a value from MY_MAP, use the expression $P{MY_MAP}.get(<theKeyToBeTransaled>)

The other option is to load a ResourceBundle and passed it to the report using the net.sf.jasperreports.engine.JRParameter#REPORT_RESOURCE_BUNDLE key... Then, inside the report, use the built-in expression: str(<theKeyToBeTransaled>)

Hope this help...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM