Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Scripting and Report Engine
Scripting and Report Engine [message #713607] Mon, 08 August 2011 16:37 Go to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
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 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
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 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #714220 is a reply to message #713967] Wed, 10 August 2011 05:02 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
Messages: 30
Registered: July 2011
Member
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 #714226 is a reply to message #714220] Wed, 10 August 2011 05:10 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #714227 is a reply to message #714220] Wed, 10 August 2011 05:47 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
Messages: 30
Registered: July 2011
Member
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 #714247 is a reply to message #714227] Wed, 10 August 2011 06:33 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #714261 is a reply to message #714247] Wed, 10 August 2011 07:15 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
Messages: 30
Registered: July 2011
Member
Thank you :/
Iam currently trying to get it to Work Via
BrowserFunction of the SWTBrowser,
this should enable me to call Java Classes Functions instead of an JavaScript Functions, but i could get it to run yet :/
Re: Scripting and Report Engine [message #714274 is a reply to message #714261] Wed, 10 August 2011 08:06 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
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&amp;v=2&amp;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 #714369 is a reply to message #714274] Wed, 10 August 2011 12:40 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
Messages: 30
Registered: July 2011
Member
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 #714462 is a reply to message #714369] Wed, 10 August 2011 14:54 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 Go to previous messageGo to next message
Johannes.Koshy is currently offline Johannes.KoshyFriend
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 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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
Re: Scripting and Report Engine [message #716337 is a reply to message #716182] Wed, 17 August 2011 05:39 Go to previous message
Johannes.Koshy is currently offline Johannes.KoshyFriend
Messages: 30
Registered: July 2011
Member
Thank you again, ill try it this way
Previous Topic:Aggregating data from two different data sets
Next Topic:Table cell data invisible in 2.6.2
Goto Forum:
  


Current Time: Sat Apr 27 03:22:02 GMT 2024

Powered by FUDForum. Page generated in 0.06673 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top