Home » Archived » BIRT » Scripting and Report Engine
Scripting and Report Engine [message #713607] |
Mon, 08 August 2011 16:37 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Hi, i have several Problems regarding skripting.
Iam still trying to deploy the report engine 2.6 in ouer RCP application, but still cant
get some Futures to work. Iam using the HTML output within an SWT Browser, java scrip is supportet.
For Example, iam trying to invoke methods of a instance of a Object from within
the Report, by first adding the Object to the AppContext via:
HashMap cont = (HashMap)config.getAppContext();
cont.put("listener", this);
config.setAppContext(cont);
and the calling it from the for example, open script via:
reportContext.getAppContext().get("listener").muh();
And this does work.
But when i try the same in the Script of an Series for a Mouse Clicked Event, it does not work.
Just a call to alert(valueData) does work.
My Intention on the longrun is, to pass certain Events on to my Application and handle them there or invoke a rerun of the report.
Another Question i have is the following:
Is it possible to bind a parameter to a Series Label?
i tried the following, with no effekt:
function beforeDrawSeriesTitle( series, label, icsc )
{
label.getCaption().setValue(params["hostName"]);
}
I appended my Report
|
|
|
Re: Scripting and Report Engine [message #713664 is a reply to message #713607] |
Mon, 08 August 2011 18:47 |
|
Interactivity on a chart is actually client side script where calling
your Java class is server side script. To get around this you will need
to add a script tag in a Text element that calls your server side
classes and assigns them to a client side variable. Take a look at the
attached example. When you see <VALUE-OF> in the script tag it is
calling the server side functions and creating client side variables
that you can then reference from chart interactivity.
On the second question do it like:
var txt =
icsc.getExternalContext().getScriptable().getParameterValue("hostName");
label.getCaption().setValue(txt);
Jason
On 8/8/2011 12:37 PM, Johannes.Koshy wrote:
> Hi, i have several Problems regarding skripting.
> Iam still trying to deploy the report engine 2.6 in ouer RCP application, but still cant
> get some Futures to work. Iam using the HTML output within an SWT Browser, java scrip is supportet.
>
> For Example, iam trying to invoke methods of a instance of a Object from within
> the Report, by first adding the Object to the AppContext via:
> HashMap cont = (HashMap)config.getAppContext();
> cont.put("listener", this);
> config.setAppContext(cont);
>
> and the calling it from the for example, open script via:
>
> reportContext.getAppContext().get("listener").muh();
>
> And this does work.
>
> But when i try the same in the Script of an Series for a Mouse Clicked Event, it does not work.
> Just a call to alert(valueData) does work.
>
> My Intention on the longrun is, to pass certain Events on to my Application and handle them there or invoke a rerun of the report.
>
>
>
> Another Question i have is the following:
>
> Is it possible to bind a parameter to a Series Label?
> i tried the following, with no effekt:
>
> function beforeDrawSeriesTitle( series, label, icsc )
> {
> label.getCaption().setValue(params["hostName"]);
> }
>
> I appended my Report
|
|
|
Re: Scripting and Report Engine [message #713822 is a reply to message #713664] |
Tue, 09 August 2011 06:39 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Thank you for your help, its my first on Java Script :/...
but i could not yet, get it to work, i tried these both:
var listener = <VALUE-OF>var finals=reportContext.getAppContext().get("listener");</VALUE-OF>
var listener = <VALUE-OF>reportContext.getAppContext().get("listener");</VALUE-OF>
with
function ShowEventData(evt, categoryData, valueData, valueSeriesName, legendItemText, legendItemValue, axisLabel) {
alert(valueData);
listener.muh();
//alert(axisLabel);
}
</script>
The Alert does work, but the listener method doesn get invoked, what did i get wrong?
|
|
|
Re: Scripting and Report Engine [message #713967 is a reply to message #713822] |
Tue, 09 August 2011 13:50 |
|
You are trying to call a Java Object call in client side script which
will not work. In the example I posted I converted a Java array to a
JavaScript array. So in your case if the function muh returns a string
you could set it up like:
var listener =
<VALUE-OF>reportContext.getAppContext().get("listener").muh();</VALUE-OF>
and then alert it.
Jason
On 8/9/2011 2:39 AM, Johannes.Koshy wrote:
> Thank you for your help, its my first on Java Script :/...
> but i could not yet, get it to work, i tried these both:
> var listener = <VALUE-OF>var
> finals=reportContext.getAppContext().get("listener");</VALUE-OF>
> var listener =
> <VALUE-OF>reportContext.getAppContext().get("listener");</VALUE-OF>
> with
> function ShowEventData(evt, categoryData, valueData, valueSeriesName,
> legendItemText, legendItemValue, axisLabel) {
>
> alert(valueData);
> listener.muh();
>
> //alert(axisLabel);
> }
> </script>
> The Alert does work, but the listener method doesn get invoked, what did
> i get wrong?
>
|
|
|
Re: Scripting and Report Engine [message #713971 is a reply to message #713822] |
Tue, 09 August 2011 13:50 |
|
You are trying to call a Java Object call in client side script which
will not work. In the example I posted I converted a Java array to a
JavaScript array. So in your case if the function muh returns a string
you could set it up like:
var listener =
<VALUE-OF>reportContext.getAppContext().get("listener").muh();</VALUE-OF>
and then alert it.
Jason
On 8/9/2011 2:39 AM, Johannes.Koshy wrote:
> Thank you for your help, its my first on Java Script :/...
> but i could not yet, get it to work, i tried these both:
> var listener = <VALUE-OF>var
> finals=reportContext.getAppContext().get("listener");</VALUE-OF>
> var listener =
> <VALUE-OF>reportContext.getAppContext().get("listener");</VALUE-OF>
> with
> function ShowEventData(evt, categoryData, valueData, valueSeriesName,
> legendItemText, legendItemValue, axisLabel) {
>
> alert(valueData);
> listener.muh();
>
> //alert(axisLabel);
> }
> </script>
> The Alert does work, but the listener method doesn get invoked, what did
> i get wrong?
>
|
|
| |
Re: Scripting and Report Engine [message #714226 is a reply to message #714220] |
Wed, 10 August 2011 05:10 |
|
You could always make the interactivity script call some js that calls
back to a java object using a servlet or AJAX.
Jason
On 8/10/2011 1:02 AM, Johannes.Koshy wrote:
> Ah hokay, so its not possible to tell my Java Application, that the
> Event has been invoked?
> cause i can only give my JavaScript Information from my Java App but not
> vice versa?
|
|
| |
Re: Scripting and Report Engine [message #714247 is a reply to message #714227] |
Wed, 10 August 2011 06:33 |
|
Value of tags are evaluated at the runtime so the muh function would be
called then not when the user clicked on a chart element.
Jason
On 8/10/2011 1:47 AM, Johannes.Koshy wrote:
> Wait, shouldnt just
> <VALUE-OF>reportContext.getAppContext().get("listener").muh();</VALUE-OF>
>
> I mean i dont need the return value just the execution of muh() to alert
> my Listener of an Event,
> could i also pass local arguements within <VALUE-OF>? so i could pass
> the Data Value?
|
|
| |
Re: Scripting and Report Engine [message #714274 is a reply to message #714261] |
Wed, 10 August 2011 08:06 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Is there a Way for me in the Birt Report Designer to get the Declaration of my JavaScript method to
the Header of the page, like in this example:
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=false" type="text/javascript"></script> <script type="text/javascript"> var map; function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); map.setUIToDefault(); // Callback to Java from JavaScript theJavaFunction(map.getCenter().lat(), map.getCenter().lng()); } } function createMarker(){ var lat = map.getCenter().lat(); var lng = map.getCenter().lng(); var point = new GLatLng(lat,lng); var d=new Date(); var marker = new GMarker(point, {draggable: true}); GEvent.addListener(marker, "dragstart", function() { map.closeInfoWindow(); }); GEvent.addListener(marker, "dragend", function() { }); map.addOverlay(marker); addMassiveData(); } function addMassiveData(){ // Add 10 markers to the map at random locations var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var lngSpan = northEast.lng() - southWest.lng(); var latSpan = northEast.lat() - southWest.lat(); for (var i = 0; i < 100; i++) { var point = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()); map.addOverlay(new GMarker(point)); } } </script> </head>
|
|
| |
Re: Scripting and Report Engine [message #714462 is a reply to message #714369] |
Wed, 10 August 2011 14:54 |
|
Sounds good. If you are calling this in an swt browser I believe you
can enable a callback from the chart engine to a class in your app. I
just assumed this was across the web. If you look at this again and
need it I will try to build you an example.
Jason
On 8/10/2011 8:40 AM, Johannes.Koshy wrote:
> I did it within the rcp application, did seem like the most
> straitforward approach
>
> thank you for you help and sry for the repeated posting, but i cant edit
> my posts at work, just as i cant create a new thread :/...damn scanner
> sees "Weapons and Pornographie"
|
|
|
Re: Scripting and Report Engine [message #715988 is a reply to message #714462] |
Tue, 16 August 2011 07:17 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
I did get it to work by using BrowserFunction of the SWT Browser.
But by now i came along another similar problem.
I want to use a calculated Page variable within the Client sided script.
For Example, this is invoked when i click a on a value series, where i wanted vars["calced"] to be the Value
32000 or similar.
dispatchToJava(5,"102",categoryData,valueData,<VALUE-OF>vars["calced"]</VALUE-OF>); or
dispatchToJava(5,"102",categoryData,valueData,vars["calced"].value); and combination of these
did not Work.
I Thought since, the calculated Variable is a constant after the report is compiled, it would be possible.
thank you
|
|
|
Re: Scripting and Report Engine [message #716182 is a reply to message #715988] |
Tue, 16 August 2011 15:51 |
|
is dispatchToJava a js function in a text element in the report? If so
try adding a local var to this function like:
function dispatchToJava(5,"102",categoryData,valueData){
var tst = <VALUE-OF>vars["calced"]</VALUE-OF>;
}
Jason
On 8/16/2011 3:17 AM, Johannes.Koshy wrote:
> I did get it to work by using BrowserFunction of the SWT Browser.
>
> But by now i came along another similar problem.
> I want to use a calculated Page variable within the Client sided script.
> For Example, this is invoked when i click a on a value series, where i
> wanted vars["calced"] to be the Value 32000 or similar.
> dispatchToJava(5,"102",categoryData,valueData,<VALUE-OF>vars["calced"]</VALUE-OF>);
> or
> dispatchToJava(5,"102",categoryData,valueData,vars["calced"].value); and
> combination of these did not Work.
>
> I Thought since, the calculated Variable is a constant after the report
> is compiled, it would be possible.
>
> thank you
|
|
| |
Goto Forum:
Current Time: Fri Sep 27 23:09:50 GMT 2024
Powered by FUDForum. Page generated in 0.06624 seconds
|