Home
Analytics
Dynamic Labels
Megha Nidhi Dahal
Hello Community,
I'm trying to generate a report with dynamic labels. Localization using properties file won't help me (I think) as the same application/designer should produce output in multiple languages based upon the partner's locale. Also, the labels are configured by user in the database and expects it to be reflected in the report.
There are two questions I have:
1. Can I write the .properties file in runtime and link it to the designer? I may not be able to place the file where BIRT expects, but can very well pass the path of the file to BIRT.
2. I could create a dataSet upon the labels table and read the column values from this dataSet. Now if I do this, I will get multiple key value rows, one for each label in the dataSet. The key would indeed be unique. Now, is there any way that I can use this dataSet as a map? Like I would say, get me the value where key is 'Name' and use it in the labels?
Any help is highly appreciated. Also if there is a better way I'm open to it.
Arpan
Find more posts tagged with
Comments
mwilliams
If you did it the second way, you could user persistent global variables to "map" the values. You could make PGV's named by the key field and the value of the translation. Or you could store the values in an array and do a key lookup loop. Just a couple thoughts.
johnw
I agree with Michael. What you can do is create a table that has your K/V pairs. In your report, you drop a table in, set its visibility to hidden, and in the onFetch event, you can populate a Java HashMap. So, you initialize the HashMap in the reports initalize or onFactory event, set it to a global variable using the reportContext.setGlobalVariable call, then in the onFetch, you retrieve, add your K/V to the map. Then, in the actual table to be display, you just retieve and lookup.
I don't see any reason why you couldn't use BIRTs localization for this, however. As long as the property files are in your class path, it shouldn't have a problem. It is also possible to use Javas property utilities to display based on a property file.
John
Megha Nidhi Dahal
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="82870" data-time="1316155016" data-date="15 September 2011 - 11:36 PM"><p>
I agree with Michael. What you can do is create a table that has your K/V pairs. In your report, you drop a table in, set its visibility to hidden, and in the onFetch event, you can populate a Java HashMap. So, you initialize the HashMap in the reports initalize or onFactory event, set it to a global variable using the reportContext.setGlobalVariable call, then in the onFetch, you retrieve, add your K/V to the map. Then, in the actual table to be display, you just retieve and lookup.<br />
<br />
I don't see any reason why you couldn't use BIRTs localization for this, however. As long as the property files are in your class path, it shouldn't have a problem. It is also possible to use Javas property utilities to display based on a property file.<br />
<br />
John<br /></p></blockquote>
John, Michael,<br />
<br />
Thanks a lot for your responses.<br />
<br />
There are a few challenges that I'm facing when I create a dataSet of key-value pairs.<br />
I was successfully able to create a map and initialize it with the values coming from the dataSet. However, this will restrict me to use any of these labels in the master page. I can use these labels just as I wanted in the detail pages, but since its not possible to insert an iterative pallete like lists/tabels in Master page, I do not get the whole data.<br />
<br />
What is the order of execution if I have multiple master pages? Are all master pages executed before coming to the detail pages, or first the master page and linked detail pages will be executed? If its later then probably I have a way out.<br />
<br />
Any help is highly appreciated.<br />
<br />
Best Regards<br />
Arpan
Megha Nidhi Dahal
Hi,
I have found a way to do it. Its highly inspired from whatever you have suggested. I wrote a POJO which has a static method that accepts fileName as parameter and creates a map from the file.
I imported this class in initialize() event and used this POJO to return me a map. Filename would be passed as a report parameter.
Later on, I use this map to fetch the values for a predefined set of keys.
Thanks a lot!
Megha
johnw
Someone had a similar question, and I wrote up an example here:
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1419-using-resource-bundles-in-birt/
This should do what your looking for using Javas ResourceBundle class. It will work in any master page without an issue. Its very similar to what you are doing.
Megha Nidhi Dahal
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="83293" data-time="1317051670" data-date="26 September 2011 - 08:41 AM"><p>
Someone had a similar question, and I wrote up an example here: <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1419-using-resource-bundles-in-birt/'>http://www.birt-exchange.org/org/devshare/designing-birt-reports/1419-using-resource-bundles-in-birt/</a><br
/>
<br />
This should do what your looking for using Javas ResourceBundle class. It will work in any master page without an issue. Its very similar to what you are doing.<br /></p></blockquote>
Yes I went through your article. Thanks for sharing just a wonderful idea!