Home
Analytics
Using .properties file to alter data
Elja
<p>Hello.</p>
<p> </p>
<p>I've been searching for a way to use .properties file to alter the data displayed in my report - with no luck.</p>
<p> </p>
<p>What I need to do is to display another value in the report data field (than what is found in the database). I managed to bind the "Keskeytys_syy.properties" -file from Property Editor - Resources. This .properties -file includes the following bindings:</p>
<p>kunta.keskeytyssaannot.syykoodi.KESKEYTYS_LOMA=Loma<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_SAIRAALA=Sairaala<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_KUOLEMA=Kuolema<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_MUU_SYY=Muu syy</p>
<p> </p>
<p>For example, I'd like to show on the report the shorter values like "Loma", when the value for "syykoodi"-field is "KESKEYTYS_LOMA".</p>
<p>My colleagues told this problem I'm having won't probably be resolved on the database -level.</p>
<p> </p>
<p>ACTIONS:</p>
<p>A) I was able to use this .properties file for a text field with no problem.</p>
<p>B) I was also able to use the .properties file for mapping data field each value individually from "Property Editor - Data - Map". (data field)</p>
<p> </p>
<p>-> But this isn't a dynamic way to do this. If there are any changes made to the display values OR some extra values are added to the kunta.keskeytyssaannot.syykodi -column, they are not shown on the report.</p>
<p>Better way would be just to update the .properties file if needed.</p>
<p> </p>
<p>QUESTION: Is there a way to display dynamically the shorter values (Loma, Sairaala, Kuolema, Muu syy) according to the value from the database? With only addressing the .properties value and without any actual mapping "value by value"?</p>
<p> </p>
<p>- Elja</p>
Find more posts tagged with
Comments
JFreeman
<p>The .properties file is intended to be used for localization/internationalization which means it is created to take and convert static values.</p>
<p> </p>
<p>Trying to use it in a dynamic scenario like yours is probably why you are running into these issues as it was not intended to be used that way.</p>
<p> </p>
<p>You could instead create a computed column and then use some logic with javascript to decide which shorter values to display.</p>
Elja
<p>Hey JFreeman.</p>
<p> </p>
<p>Thanks a lot for your answer. I was thinking about the properties file intended to being used with static values after searching and reading info on the matter quite a lot.</p>
<p> </p>
<p>Do you know whether I'm able to read the .properties file via javascript? That'd be a solution I'm searching for and I could proceed with that..</p>
<p> </p>
<p>- Elja</p>
JFreeman
<p>It should be possible to read the .properties file via javascript like you would with any other text file.</p>
<p> </p>
<p>Let me know if you have issues and I can see about creating a quick example.</p>
micajblock
<p>If you provide sample data and a properties file and I can build an example.</p>
Elja
<p>Thanks a lot. I can post the rptdesign + properties-file and explain the idea. The report is built in our environment, so it can't be used over there. But let's try!</p>
<p> </p>
<p>I'll give an explanation (below) on what I'm trying to do and attach a screen shot and the rptdesign.</p>
<p> </p>
<p>The Keskeytys_syy.properties -file cannot be attached (not even in a zip file), so I'll paste the contents here:</p>
<p> </p>
<p>********************************************************************************</p>
<p>#<br>
# 28.4.2015<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_LOMA=Loma<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_SAIRAALA=Sairaala<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_KUOLEMA=Kuolema<br>
kunta.keskeytyssaannot.syykoodi.KESKEYTYS_MUU_SYY=Muu syy<br>
Palvelu=Palvelun nimi<br>
welcome=Hello<br>
********************************************************************************</p>
<p> </p>
<p>Explanation:</p>
<p>It'd be nice to alter the data shown in "kirjauksen_syykoodi" so that it would not show the actual info retreived from the database: (KESKEYTYS_LOMA, KESKEYTYS_SAIRAALA, KESKEYTYS_KUOLEMA, KESKEYTYS_MUU_SYY).</p>
<p>But instead would present the shorter version shown in properties above: ('Loma', 'Sairaala', 'Kuolema', 'Muu syy').</p>
<p> </p>
<p>The idea is that if/when the list of the codes is altered, it'd be enough to reload the .properties file (representing the new values) and not have to touch the actual code/formula in order to be able to present the values correctly inside the "kirjauksen_syykoodi" -field.</p>
<p> </p>
<p>I was thinking about a logic where the .properties -file would be parsed based on the equal (=) -character. **When database value "KESKEYTYS.****" equals the string on the left side of the "=" -character in .properties, show the string on the right side of the "=" -character... ***</p>
<p> </p>
<p>Thanks a lot, Elja</p>
micajblock
<p>You use code like this in a data item (see attached example):</p>
<pre class="_prettyXprint">
reportContext.getMessage("kunta.keskeytyssaannot.syykoodi." + row["kirjauksen_syykoodi"])</pre>