Reputation: 1
Firstly, is it possible to develop with Javascript only(not using any Java function)? I can't get/set values from items like labels/table/chart is it possible to call them from the HTML button item?
I'm currently using Openlayers and BIRT. The map would be inside the BIRT report, and by clicking a certain area in the map it should get the value and store it in an item like label. The problem is how to set/get from an item.
I've tried using same procedures as Java/C# wherein a getting or setting a value on text field named txt1 would be as simple as. txt1.setValue("hi"); How do i do the same thing using Javascript on BIRT?
Upvotes: 0
Views: 2860
Reputation: 4332
First you have to be comfortable with the fact that although BIRT scripting is called "javascript", it is actually a server-side API when OpenLayers is a client-side javascript API. In particular, it means we can't directly access to report items from OpenLayers events.
We can workaround this by putting all item values we need in client-side variables, so that we can use them in a client-side javascript code later. This can be achieved by creating hidden text elements set to "HTML" in your BIRT report, and then store some values in an object. For example this is how this sample works.
At the beginning of the report we initialize a client-side object named "report" in a hidden HTML text element such below. For instance let's say our report has two parameters "param1" and "param2", we can store them using "VALUE-OF" tag:
<script>
report={};
report.param1='<VALUE-OF>params["param1"].value</VALUE-OF>';
report.param2='<VALUE-OF>params["param2"].value</VALUE-OF>';
report.countries={};
</script>
Now from OpenLayers events you can get a report parameter just by using the expression report.param1
Notice in this example we have also initialized a table object named "countries". It can be used if we need to access values of datafields of a birt table, in order to use it later in client-side javascript. To achieve this, we add another hidden HTML text element in table rows, storing informations we want. In this example we store a numeric value associated to each country of the table:
<script>
report.countries['<VALUE-OF>row["countryID"]</VALUE-OF>']=<VALUE-OF>row["value"]</VALUE-OF>;
</script>
In Openlayers events, from a variable named "myCountryID" we can now access to values provided by this BIRT table with an expression such report.countries[myCountryID]
Concerning how to "set" report elements from javascript, given the fact a birt report is generated on server-side it is not possible. However we can still create HTML text elements with explicit identifiers, and then set these elements dynamically with a regular javascript code.
Upvotes: 1